Commit e9d6dc3d authored by Kirill Unitsaev's avatar Kirill Unitsaev

preset: add --format flag to info command

- Add JSON output support to preset info command - Update ShowProfilesInfo to accept jsonFormat parameter
parent ed93b23b
...@@ -396,10 +396,14 @@ func createProfile(profileName string, prof config.PresetProfile, dryRun bool, r ...@@ -396,10 +396,14 @@ func createProfile(profileName string, prof config.PresetProfile, dryRun bool, r
processProfile(prof, dryRun, res) processProfile(prof, dryRun, res)
} }
func ShowProfilesInfo() { func ShowProfilesInfo(jsonFormat bool) {
profiles := config.Env.Preset.Profiles profiles := config.Env.Preset.Profiles
if len(profiles) == 0 { if len(profiles) == 0 {
if jsonFormat {
ui.PrintJSON([]ui.JSONItem{})
return
}
color.Red("Нет доступных профилей") color.Red("Нет доступных профилей")
return return
} }
...@@ -416,6 +420,11 @@ func ShowProfilesInfo() { ...@@ -416,6 +420,11 @@ func ShowProfilesInfo() {
}) })
} }
if jsonFormat {
ui.PrintJSON(ui.TreeItemsToJSON(items))
return
}
ui.RenderTree(ui.RenderTreeOptions{ ui.RenderTree(ui.RenderTreeOptions{
Title: "Profiles", Title: "Profiles",
Items: items, Items: items,
...@@ -429,7 +438,7 @@ func presetApplyCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -429,7 +438,7 @@ func presetApplyCommand(ctx context.Context, cmd *cli.Command) error {
profileName := cmd.Args().Get(0) profileName := cmd.Args().Get(0)
if profileName == "" { if profileName == "" {
ShowProfilesInfo() ShowProfilesInfo(false)
return nil return nil
} }
...@@ -475,6 +484,6 @@ func presetApplyAllCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -475,6 +484,6 @@ func presetApplyAllCommand(ctx context.Context, cmd *cli.Command) error {
} }
func presetInfoCommand(ctx context.Context, cmd *cli.Command) error { func presetInfoCommand(ctx context.Context, cmd *cli.Command) error {
ShowProfilesInfo() ShowProfilesInfo(config.IsJSON(cmd))
return nil return nil
} }
...@@ -14,8 +14,11 @@ func CommandList() *cli.Command { ...@@ -14,8 +14,11 @@ func CommandList() *cli.Command {
Usage: "Manage preset configuration profiles", Usage: "Manage preset configuration profiles",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "info", Name: "info",
Usage: "Show information about a preset profiles", Usage: "Show information about a preset profiles",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: presetInfoCommand, Action: presetInfoCommand,
}, },
{ {
......
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