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 { ...@@ -168,6 +168,9 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
modules := manager.GetModulesList(user, filter) modules := manager.GetModulesList(user, filter)
if len(modules) == 0 { if len(modules) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
return fmt.Errorf("нет доступных модулей") return fmt.Errorf("нет доступных модулей")
} }
...@@ -191,6 +194,10 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -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{ ui.RenderTree(ui.RenderTreeOptions{
Title: "Modules", Title: "Modules",
Items: items, Items: items,
......
...@@ -92,6 +92,7 @@ func CommandList() *cli.Command { ...@@ -92,6 +92,7 @@ func CommandList() *cli.Command {
Aliases: []string{"f"}, Aliases: []string{"f"},
Value: "all", Value: "all",
}, },
config.FormatFlag,
}, },
Action: HyprlandInfoModulesCommand, Action: HyprlandInfoModulesCommand,
}, },
...@@ -131,13 +132,19 @@ func CommandList() *cli.Command { ...@@ -131,13 +132,19 @@ func CommandList() *cli.Command {
Usage: "Hyprland vars", Usage: "Hyprland vars",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "list", Name: "list",
Usage: "vars list", Usage: "vars list",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandVarListCommand, Action: HyprlandVarListCommand,
}, },
{ {
Name: "info", Name: "info",
Usage: "vars info", Usage: "vars info",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandVarInfoCommand, Action: HyprlandVarInfoCommand,
}, },
{ {
...@@ -164,8 +171,11 @@ func CommandList() *cli.Command { ...@@ -164,8 +171,11 @@ func CommandList() *cli.Command {
Usage: "Hyprland plugins", Usage: "Hyprland plugins",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "list", Name: "list",
Usage: "Hyprland plugins list", Usage: "Hyprland plugins list",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: HyprlandPluginListCommand, Action: HyprlandPluginListCommand,
}, },
{ {
...@@ -185,6 +195,7 @@ func CommandList() *cli.Command { ...@@ -185,6 +195,7 @@ func CommandList() *cli.Command {
Aliases: []string{"f"}, Aliases: []string{"f"},
Value: "all", Value: "all",
}, },
config.FormatFlag,
}, },
Action: HyprlandPluginInfoCommand, Action: HyprlandPluginInfoCommand,
}, },
......
...@@ -17,6 +17,15 @@ func HyprlandPluginListCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -17,6 +17,15 @@ func HyprlandPluginListCommand(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
list := manager.GetPluginsList(cmd.String("filter")) 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")) fmt.Println(strings.Join(list, "\n"))
return nil return nil
} }
...@@ -37,6 +46,9 @@ func HyprlandPluginInfoCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -37,6 +46,9 @@ func HyprlandPluginInfoCommand(ctx context.Context, cmd *cli.Command) error {
} }
plugins := manager.GetPluginsList(cmd.String("filter")) plugins := manager.GetPluginsList(cmd.String("filter"))
if len(plugins) == 0 { if len(plugins) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
return fmt.Errorf("нет доступных плагинов") return fmt.Errorf("нет доступных плагинов")
} }
...@@ -59,6 +71,10 @@ func HyprlandPluginInfoCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -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{ ui.RenderTree(ui.RenderTreeOptions{
Title: "Plugins", Title: "Plugins",
Items: items, Items: items,
......
...@@ -21,6 +21,14 @@ func HyprlandVarListCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -21,6 +21,14 @@ func HyprlandVarListCommand(ctx context.Context, cmd *cli.Command) error {
return err 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 { for _, v := range manager.Vars {
fmt.Println(v.Name) fmt.Println(v.Name)
} }
...@@ -37,6 +45,9 @@ func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -37,6 +45,9 @@ func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error {
info := manager.GetVarList() info := manager.GetVarList()
if len(info) == 0 { if len(info) == 0 {
if config.IsJSON(cmd) {
return ui.PrintJSON([]ui.JSONItem{})
}
color.Yellow("Нет переменных в конфигурации") color.Yellow("Нет переменных в конфигурации")
return nil return nil
} }
...@@ -53,6 +64,10 @@ func HyprlandVarInfoCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -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{ ui.RenderTree(ui.RenderTreeOptions{
Title: "Vars", Title: "Vars",
Items: items, 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