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