Commit ed93b23b authored by Kirill Unitsaev's avatar Kirill Unitsaev

hyprland: add --format flag to info/list commands

- Add --format flag to var list/info, module info, plugin list/info - Support JSON output for all info/list commands
parent e38fe06d
......@@ -168,6 +168,9 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
modules := manager.GetModulesList(user, filter)
if len(modules) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
return fmt.Errorf("нет доступных модулей")
}
......@@ -191,6 +194,10 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
})
}
if config.IsJSON(cmd) {
return ui.PrintJSON(ui.TreeItemsToJSON(items))
}
ui.RenderTree(ui.RenderTreeOptions{
Title: "Modules",
Items: items,
......
......@@ -92,6 +92,7 @@ func CommandList() *cli.Command {
Aliases: []string{"f"},
Value: "all",
},
config.FormatFlag,
},
Action: HyprlandInfoModulesCommand,
},
......@@ -131,13 +132,19 @@ func CommandList() *cli.Command {
Usage: "Hyprland vars",
Commands: []*cli.Command{
{
Name: "list",
Usage: "vars list",
Name: "list",
Usage: "vars list",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandVarListCommand,
},
{
Name: "info",
Usage: "vars info",
Name: "info",
Usage: "vars info",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandVarInfoCommand,
},
{
......@@ -164,8 +171,11 @@ func CommandList() *cli.Command {
Usage: "Hyprland plugins",
Commands: []*cli.Command{
{
Name: "list",
Usage: "Hyprland plugins list",
Name: "list",
Usage: "Hyprland plugins list",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandPluginListCommand,
},
{
......@@ -185,6 +195,7 @@ func CommandList() *cli.Command {
Aliases: []string{"f"},
Value: "all",
},
config.FormatFlag,
},
Action: HyprlandPluginInfoCommand,
},
......
......@@ -17,6 +17,15 @@ func HyprlandPluginListCommand(ctx context.Context, cmd *cli.Command) error {
return err
}
list := manager.GetPluginsList(cmd.String("filter"))
if config.IsJSON(cmd) {
items := make([]ui.JSONItem, len(list))
for i, name := range list {
items[i] = ui.JSONItem{Name: name}
}
return ui.PrintJSON(items)
}
fmt.Println(strings.Join(list, "\n"))
return nil
}
......@@ -37,6 +46,9 @@ func HyprlandPluginInfoCommand(ctx context.Context, cmd *cli.Command) error {
}
plugins := manager.GetPluginsList(cmd.String("filter"))
if len(plugins) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
return fmt.Errorf("нет доступных плагинов")
}
......@@ -59,6 +71,10 @@ func HyprlandPluginInfoCommand(ctx context.Context, cmd *cli.Command) error {
})
}
if config.IsJSON(cmd) {
return ui.PrintJSON(ui.TreeItemsToJSON(items))
}
ui.RenderTree(ui.RenderTreeOptions{
Title: "Plugins",
Items: items,
......
......@@ -21,6 +21,14 @@ func HyprlandVarListCommand(ctx context.Context, cmd *cli.Command) error {
return err
}
if config.IsJSON(cmd) {
items := make([]ui.JSONItem, len(manager.Vars))
for i, v := range manager.Vars {
items[i] = ui.JSONItem{Name: v.Name, Value: v.Value}
}
return ui.PrintJSON(items)
}
for _, v := range manager.Vars {
fmt.Println(v.Name)
}
......@@ -37,6 +45,9 @@ func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error {
info := manager.GetVarList()
if len(info) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
color.Yellow("Нет переменных в конфигурации")
return nil
}
......@@ -53,6 +64,10 @@ func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error {
})
}
if config.IsJSON(cmd) {
return ui.PrintJSON(ui.TreeItemsToJSON(items))
}
ui.RenderTree(ui.RenderTreeOptions{
Title: "Vars",
Items: items,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment