diff --git a/internal/commands/config/list_profiles_internal.go b/internal/commands/config/list_profiles_internal.go index 2b56a152..a8aa8c01 100644 --- a/internal/commands/config/list_profiles_internal.go +++ b/internal/commands/config/list_profiles_internal.go @@ -1,21 +1,40 @@ package config_internal import ( + "github.com/fatih/color" + "github.com/pingidentity/pingcli/internal/logger" "github.com/pingidentity/pingcli/internal/output" "github.com/pingidentity/pingcli/internal/profiles" ) func RunInternalConfigListProfiles() { + l := logger.Get() + profileNames := profiles.GetMainConfig().ProfileNames() activeProfile := profiles.GetMainConfig().ActiveProfile().Name() listStr := "Profiles:\n" + + // We need to enable/disable colorize before applying the color to the string below. + output.SetColorize() + activeFmt := color.New(color.Bold, color.FgGreen).SprintFunc() + for _, profileName := range profileNames { if profileName == activeProfile { - listStr += "- " + profileName + " (active)\n" + listStr += "- " + profileName + activeFmt(" (active)") + " \n" } else { listStr += "- " + profileName + "\n" } + + description, err := profiles.GetMainConfig().ProfileViperValue(profileName, "description") + if err != nil { + l.Warn().Msgf("Cannot retrieve profile description for profile %s: %v", profileName, err) + continue + } + + if description != "" { + listStr += " " + description + "\n" + } } output.Print(output.Opts{ diff --git a/internal/output/output.go b/internal/output/output.go index 607258fb..f45a96a3 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -39,7 +39,7 @@ const ( ENUM_RESULT_FAILURE Result = "Failure" ) -func Print(output Opts) { +func SetColorize() { colorizeOutput, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { color.NoColor = false @@ -51,6 +51,11 @@ func Print(output Opts) { color.NoColor = !colorizeOutputBool } } +} + +func Print(output Opts) { + + SetColorize() outputFormat, err := profiles.GetOptionValue(options.RootOutputFormatOption) if err != nil { diff --git a/internal/profiles/viper.go b/internal/profiles/viper.go index 34aa8846..064eebdc 100644 --- a/internal/profiles/viper.go +++ b/internal/profiles/viper.go @@ -164,6 +164,7 @@ func (m MainConfig) DeleteProfile(pName string) (err error) { } // Get all profile names from config.yaml configuration file +// Returns a sorted slice of profile names func (m MainConfig) ProfileNames() (profileNames []string) { keySet := make(map[string]struct{}) mainViperKeys := m.ViperInstance().AllKeys() @@ -180,6 +181,8 @@ func (m MainConfig) ProfileNames() (profileNames []string) { } } + slices.Sort(profileNames) + return profileNames }