From 9dd3781f41359f78c9543af8f093baa96f71e50c Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Thu, 17 Oct 2024 17:34:25 +0200 Subject: [PATCH 1/3] PDI-2056: [UAT] Update --profile Flags Functionality - Make --active-profile global flag be --profile instead. - Have the --profile flag only apply for this instance of command it is specified, where it does not update nor affect the configuration file's activeProfile configuration. - Update config commands to use --profile-name instead of --profile to avoid flag collisions with the global flag. --- cmd/platform/platform.go | 2 +- cmd/root.go | 22 +++++++++++---- cmd/root_test.go | 14 +++++----- docs/tool-configuration/configuration-key.md | 2 +- internal/configuration/config/get.go | 2 +- internal/configuration/config/set.go | 2 +- internal/configuration/config/unset.go | 2 +- internal/configuration/options/options.go | 2 ++ internal/configuration/request/request.go | 18 ++++++------ internal/configuration/root/root.go | 29 +++++++++++++++----- internal/profiles/viper.go | 25 ++++++++++++++--- 11 files changed, 83 insertions(+), 37 deletions(-) diff --git a/cmd/platform/platform.go b/cmd/platform/platform.go index a291a13a..19e03d7e 100644 --- a/cmd/platform/platform.go +++ b/cmd/platform/platform.go @@ -10,7 +10,7 @@ func NewPlatformCommand() *cobra.Command { When multiple products are configured in the CLI, the platform command can be used to manage one or more products collectively. -The --active-profile command switch can be used to specify the profile of Ping products to be managed.`, +The --profile command switch can be used to specify the profile of Ping products to be managed.`, Short: "Administer and manage the Ping integrated platform.", Use: "platform", } diff --git a/cmd/root.go b/cmd/root.go index 3ddd9115..1806532b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -47,7 +47,7 @@ func NewRootCommand() *cobra.Command { ) cmd.PersistentFlags().AddFlag(options.RootConfigOption.Flag) - cmd.PersistentFlags().AddFlag(options.RootActiveProfileOption.Flag) + cmd.PersistentFlags().AddFlag(options.RootProfileOption.Flag) cmd.PersistentFlags().AddFlag(options.RootOutputFormatOption.Flag) cmd.PersistentFlags().AddFlag(options.RootColorOption.Flag) @@ -80,7 +80,15 @@ func initViperProfile() { //Configure the main viper instance initMainViper(cfgFile) - profileName, err := profiles.GetOptionValue(options.RootActiveProfileOption) + userDefinedProfile, err := profiles.GetOptionValue(options.RootProfileOption) + if err != nil { + output.Print(output.Opts{ + Message: "Failed to get user-defined profile", + Result: output.ENUM_RESULT_FAILURE, + FatalMessage: err.Error(), + }) + } + configFileActiveProfile, err := profiles.GetOptionValue(options.RootActiveProfileOption) if err != nil { output.Print(output.Opts{ Message: "Failed to get active profile", @@ -89,12 +97,16 @@ func initViperProfile() { }) } - l.Debug().Msgf("Using configuration profile: %s", profileName) + if userDefinedProfile != "" { + l.Debug().Msgf("Using configuration profile: %s", userDefinedProfile) + } else { + l.Debug().Msgf("Using configuration profile: %s", configFileActiveProfile) + } // Configure the profile viper instance - if err := profiles.GetMainConfig().ChangeActiveProfile(profileName); err != nil { + if err := profiles.GetMainConfig().ChangeActiveProfile(configFileActiveProfile); err != nil { output.Print(output.Opts{ - Message: "Failed to set profile viper", + Message: "Failed to set active profile viper", Result: output.ENUM_RESULT_FAILURE, FatalMessage: err.Error(), }) diff --git a/cmd/root_test.go b/cmd/root_test.go index 028fe607..d55e0c6c 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -110,15 +110,15 @@ func TestRootCmd_NoValueConfigFlag(t *testing.T) { testutils.CheckExpectedError(t, err, &expectedErrorPattern) } -// Test Root Command Executes when provided the --active-profile flag -func TestRootCmd_ActiveProfileFlag(t *testing.T) { - err := testutils_cobra.ExecutePingcli(t, "--active-profile", "default") +// Test Root Command Executes when provided the --profile flag +func TestRootCmd_ProfileFlag(t *testing.T) { + err := testutils_cobra.ExecutePingcli(t, "--profile", "default") testutils.CheckExpectedError(t, err, nil) } -// Test Root Command fails when provided no value for the --active-profile flag -func TestRootCmd_NoValueActiveProfileFlag(t *testing.T) { - expectedErrorPattern := `^flag needs an argument: --active-profile$` - err := testutils_cobra.ExecutePingcli(t, "--active-profile") +// Test Root Command fails when provided no value for the --profile flag +func TestRootCmd_NoValueProfileFlag(t *testing.T) { + expectedErrorPattern := `^flag needs an argument: --profile$` + err := testutils_cobra.ExecutePingcli(t, "--profile") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } diff --git a/docs/tool-configuration/configuration-key.md b/docs/tool-configuration/configuration-key.md index 9431a594..eb133f29 100644 --- a/docs/tool-configuration/configuration-key.md +++ b/docs/tool-configuration/configuration-key.md @@ -7,7 +7,7 @@ The following parameters can be configured in Ping CLI's static configuration fi | Config File Property | Type | Equivalent Parameter | Purpose | |---|---|---|---| -| activeProfile | ENUM_STRING | --active-profile / -P | The name of the stored custom configuration profile to use. | +| activeProfile | ENUM_STRING | | The name of the stored custom configuration profile to use by default. | | color | ENUM_BOOL | --color | Show text output in color. | | outputFormat | ENUM_OUTPUT_FORMAT | --output-format / -O | Specify the console output format.

Options are: json, text.

Example: `json` | diff --git a/internal/configuration/config/get.go b/internal/configuration/config/get.go index 5e7b433d..ffdfaa27 100644 --- a/internal/configuration/config/get.go +++ b/internal/configuration/config/get.go @@ -11,7 +11,7 @@ func InitConfigGetOptions() { } func initGetProfileOption() { - cobraParamName := "profile" + cobraParamName := "profile-name" cobraValue := new(customtypes.String) defaultValue := customtypes.String("") diff --git a/internal/configuration/config/set.go b/internal/configuration/config/set.go index 952d5fd9..90dd99bf 100644 --- a/internal/configuration/config/set.go +++ b/internal/configuration/config/set.go @@ -11,7 +11,7 @@ func InitConfigSetOptions() { } func initSetProfileOption() { - cobraParamName := "profile" + cobraParamName := "profile-name" cobraValue := new(customtypes.String) defaultValue := customtypes.String("") diff --git a/internal/configuration/config/unset.go b/internal/configuration/config/unset.go index 50becd04..d8151c4c 100644 --- a/internal/configuration/config/unset.go +++ b/internal/configuration/config/unset.go @@ -11,7 +11,7 @@ func InitConfigUnsetOptions() { } func initUnsetProfileOption() { - cobraParamName := "profile" + cobraParamName := "profile-name" cobraValue := new(customtypes.String) defaultValue := customtypes.String("") diff --git a/internal/configuration/options/options.go b/internal/configuration/options/options.go index 6c5cabf0..8addec9a 100644 --- a/internal/configuration/options/options.go +++ b/internal/configuration/options/options.go @@ -60,6 +60,7 @@ func Options() []Option { PingFederateAuthenticationTypeOption, RootActiveProfileOption, + RootProfileOption, RootColorOption, RootConfigOption, RootOutputFormatOption, @@ -147,6 +148,7 @@ var ( // Root Command Options var ( RootActiveProfileOption Option + RootProfileOption Option RootColorOption Option RootConfigOption Option RootOutputFormatOption Option diff --git a/internal/configuration/request/request.go b/internal/configuration/request/request.go index e3a0f957..3d7d1e7b 100644 --- a/internal/configuration/request/request.go +++ b/internal/configuration/request/request.go @@ -89,10 +89,10 @@ func initAccessTokenOption() { defaultValue := customtypes.String("") options.RequestAccessTokenOption = options.Option{ - CobraParamName: "", // No cobra param name - CobraParamValue: nil, // No cobra param value - DefaultValue: &defaultValue, // No default value - EnvVar: "", // No environment variable + CobraParamName: "", // No cobra param name + CobraParamValue: nil, // No cobra param value + DefaultValue: &defaultValue, + EnvVar: "", // No environment variable Flag: nil, Type: options.ENUM_STRING, ViperKey: "request.accessToken", @@ -103,11 +103,11 @@ func initAccessTokenExpiryOption() { defaultValue := customtypes.Int(0) options.RequestAccessTokenExpiryOption = options.Option{ - CobraParamName: "", // No cobra param name - CobraParamValue: nil, // No cobra param value - DefaultValue: &defaultValue, // No default value - EnvVar: "", // No environment variable - Flag: nil, // No flag + CobraParamName: "", // No cobra param name + CobraParamValue: nil, // No cobra param value + DefaultValue: &defaultValue, + EnvVar: "", // No environment variable + Flag: nil, // No flag Type: options.ENUM_INT, ViperKey: "request.accessTokenExpiry", } diff --git a/internal/configuration/root/root.go b/internal/configuration/root/root.go index e8c60969..c731e0de 100644 --- a/internal/configuration/root/root.go +++ b/internal/configuration/root/root.go @@ -13,30 +13,45 @@ import ( func InitRootOptions() { initActiveProfileOption() + initProfileOption() initColorOption() initConfigOption() initOutputFormatOption() } func initActiveProfileOption() { - cobraParamName := "active-profile" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("default") + defaultValue := customtypes.String("") options.RootActiveProfileOption = options.Option{ + CobraParamName: "", // No cobra param + CobraParamValue: nil, + DefaultValue: &defaultValue, + EnvVar: "", // No env var + Flag: nil, // No flag + Type: options.ENUM_STRING, + ViperKey: "activeProfile", + } +} + +func initProfileOption() { + cobraParamName := "profile" + cobraValue := new(customtypes.String) + defaultValue := customtypes.String("") + + options.RootProfileOption = options.Option{ CobraParamName: cobraParamName, CobraParamValue: cobraValue, DefaultValue: &defaultValue, - EnvVar: "PINGCLI_ACTIVE_PROFILE", + EnvVar: "PINGCLI_PROFILE", Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "P", - Usage: "The name of the stored custom configuration profile to use.", + Usage: "The name of a configuration profile to use.", Value: cobraValue, - DefValue: "default", + DefValue: "", }, Type: options.ENUM_STRING, - ViperKey: "activeProfile", + ViperKey: "", // No viper key } } diff --git a/internal/profiles/viper.go b/internal/profiles/viper.go index 34aa8846..e07bab42 100644 --- a/internal/profiles/viper.go +++ b/internal/profiles/viper.go @@ -327,12 +327,29 @@ func GetOptionValue(opt options.Option) (pFlagValue string, err error) { if opt.ViperKey != "" && mainConfig != nil { var vValue any - if opt.ViperKey == options.RootActiveProfileOption.ViperKey { - mainViperInstance := mainConfig.ViperInstance() - if mainViperInstance != nil { - vValue = mainViperInstance.Get(opt.ViperKey) + mainViperInstance := mainConfig.ViperInstance() + // This recursive call is safe, as options.RootProfileOption.ViperKey is not set + definedProfileName, err := GetOptionValue(options.RootProfileOption) + if err != nil { + return "", err + } + + // 3 Cases: + // - 1) Viper Key is the ActiveProfile Key, get value from main viper instance + // - 2) --profile flag has been set, get value from set profile viper instance + // - 3) no --profile flag set, get value from active profile viper instance defined in main viper instance + + if opt.ViperKey == options.RootActiveProfileOption.ViperKey && mainViperInstance != nil { + // Case 1 + vValue = mainViperInstance.Get(opt.ViperKey) + } else if definedProfileName != "" { + // Case 2 + profileViperInstance := mainViperInstance.Sub(definedProfileName) + if profileViperInstance != nil { + vValue = profileViperInstance.Get(opt.ViperKey) } } else { + // Case 3 activeProfile := mainConfig.ActiveProfile() if activeProfile != nil { profileViperInstance := activeProfile.ViperInstance() From 039444e31e7ffe1beefdb809dea74e3fa9b4b058 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Thu, 17 Oct 2024 20:07:29 +0200 Subject: [PATCH 2/3] PDI-2056: Add Defaults to Usage Output - Update all PFlag structs to remove DefValue and manually add default information to Usage field. - Also remove config command logic. --- cmd/config/config.go | 25 ---- internal/commands/config/config_internal.go | 111 --------------- .../commands/config/config_internal_test.go | 132 ------------------ internal/configuration/config/add_profile.go | 9 +- internal/configuration/config/config.go | 79 ----------- .../configuration/config/delete_profile.go | 8 +- internal/configuration/config/get.go | 6 +- internal/configuration/config/set.go | 6 +- internal/configuration/config/unset.go | 6 +- internal/configuration/configuration.go | 1 - internal/configuration/options/options.go | 7 - internal/configuration/platform/export.go | 82 ++++++----- internal/configuration/request/request.go | 31 ++-- internal/configuration/root/root.go | 35 +++-- .../configuration/services/pingfederate.go | 119 +++++++++------- internal/configuration/services/pingone.go | 47 ++++--- internal/output/output.go | 6 +- 17 files changed, 203 insertions(+), 507 deletions(-) delete mode 100644 internal/commands/config/config_internal.go delete mode 100644 internal/commands/config/config_internal_test.go delete mode 100644 internal/configuration/config/config.go diff --git a/cmd/config/config.go b/cmd/config/config.go index 2811adf7..98182cca 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -4,21 +4,11 @@ import ( "github.com/spf13/cobra" ) -// const ( -// configCommandExamples = ` pingcli config -// pingcli config --profile myprofile -// pingcli config --name myprofile --description "My Profile"` -// ) - func NewConfigCommand() *cobra.Command { cmd := &cobra.Command{ - // Args: common.ExactArgs(0), - // DisableFlagsInUseLine: true, // We write our own flags in @Use attribute - // Example: configCommandExamples, Long: "Manage the configuration of the CLI, including Ping product connection parameters.\n\n" + "The Ping CLI supports the use of configuration profiles.\nConfiguration profiles can be used when connecting to multiple environments using the same Ping CLI instance, such as when managing multiple development or demonstration environments.\n\n" + "A pre-defined default profile will be used to store the configuration of the CLI.\nAdditional custom profiles can be created using the `pingcli config add-profile` command.\nTo use a custom profile, the `--profile` flag can be used on supported commands to specify the profile to use for that command.\nTo set a custom profile as the default, use the `pingcli config set-active-profile` command.", - // RunE: configRunE, Short: "Manage the CLI configuration.", Use: "config", } @@ -35,20 +25,5 @@ func NewConfigCommand() *cobra.Command { NewConfigUnsetCommand(), ) - // cmd.Flags().AddFlag(options.ConfigProfileOption.Flag) - // cmd.Flags().AddFlag(options.ConfigNameOption.Flag) - // cmd.Flags().AddFlag(options.ConfigDescriptionOption.Flag) - return cmd } - -// func configRunE(cmd *cobra.Command, args []string) error { -// l := logger.Get() -// l.Debug().Msgf("Config Subcommand Called.") - -// if err := config_internal.RunInternalConfig(os.Stdin); err != nil { -// return err -// } - -// return nil -// } diff --git a/internal/commands/config/config_internal.go b/internal/commands/config/config_internal.go deleted file mode 100644 index 9d7bf2f2..00000000 --- a/internal/commands/config/config_internal.go +++ /dev/null @@ -1,111 +0,0 @@ -package config_internal - -import ( - "fmt" - "io" - - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/input" - "github.com/pingidentity/pingcli/internal/output" - "github.com/pingidentity/pingcli/internal/profiles" -) - -func RunInternalConfig(rc io.ReadCloser) (err error) { - profileName, newProfileName, newDescription, err := readConfigOptions(rc) - if err != nil { - return fmt.Errorf("failed to update profile. %v", err) - } - - output.Print(output.Opts{ - Message: fmt.Sprintf("Updating profile '%s'...", profileName), - Result: output.ENUM_RESULT_NIL, - }) - - if err = profiles.GetMainConfig().ChangeProfileName(profileName, newProfileName); err != nil { - return fmt.Errorf("failed to update profile '%s' name to: %s. %v", profileName, newProfileName, err) - } - - if err = profiles.GetMainConfig().ChangeProfileDescription(newProfileName, newDescription); err != nil { - return fmt.Errorf("failed to update profile '%s' description to: %s. %v", newProfileName, newDescription, err) - } - - output.Print(output.Opts{ - Message: fmt.Sprintf("Profile updated. Update additional profile attributes via 'pingcli config set' or directly within the config file at '%s'", profiles.GetMainConfig().ViperInstance().ConfigFileUsed()), - Result: output.ENUM_RESULT_SUCCESS, - }) - - return nil -} - -func readConfigOptions(rc io.ReadCloser) (profileName, newName, description string, err error) { - if profileName, err = readConfigProfileNameOption(); err != nil { - return profileName, newName, description, err - } - - if newName, err = readConfigNameOption(rc); err != nil { - return profileName, newName, description, err - } - - if description, err = readConfigDescriptionOption(rc); err != nil { - return profileName, newName, description, err - } - - return profileName, newName, description, nil -} - -func readConfigProfileNameOption() (pName string, err error) { - if !options.ConfigProfileOption.Flag.Changed { - pName, err = profiles.GetOptionValue(options.RootActiveProfileOption) - } else { - pName, err = profiles.GetOptionValue(options.ConfigProfileOption) - } - - if err != nil { - return pName, err - } - - if pName == "" { - return pName, fmt.Errorf("unable to determine profile name to update") - } - - return pName, nil -} - -func readConfigNameOption(rc io.ReadCloser) (newName string, err error) { - if !options.ConfigNameOption.Flag.Changed { - newName, err = input.RunPrompt("New profile name: ", validateChangeProfileName, rc) - } else { - newName, err = profiles.GetOptionValue(options.ConfigNameOption) - } - - if err != nil { - return newName, err - } - - if newName == "" { - return newName, fmt.Errorf("unable to determine new profile name") - } - - return newName, nil -} - -func readConfigDescriptionOption(rc io.ReadCloser) (description string, err error) { - if !options.ConfigDescriptionOption.Flag.Changed { - return input.RunPrompt("New profile description: ", nil, rc) - } else { - return profiles.GetOptionValue(options.ConfigDescriptionOption) - } -} - -func validateChangeProfileName(newName string) (err error) { - oldName, err := readConfigProfileNameOption() - if err != nil { - return err - } - - if err = profiles.GetMainConfig().ValidateUpdateExistingProfileName(oldName, newName); err != nil { - return err - } - - return nil -} diff --git a/internal/commands/config/config_internal_test.go b/internal/commands/config/config_internal_test.go deleted file mode 100644 index f768746e..00000000 --- a/internal/commands/config/config_internal_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package config_internal - -import ( - "os" - "testing" - - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/customtypes" - "github.com/pingidentity/pingcli/internal/testing/testutils" - "github.com/pingidentity/pingcli/internal/testing/testutils_viper" -) - -// Test RunInternalConfig function -func Test_RunInternalConfig(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("test-profile") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - err := RunInternalConfig(os.Stdin) - if err != nil { - t.Errorf("RunInternalConfig returned error: %v", err) - } -} - -// Test RunInternalConfig function fails when existing profile name is provided -func Test_RunInternalConfig_ExistingProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("default") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. profile already exists$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when invalid profile name is provided -func Test_RunInternalConfig_InvalidProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("test-profile!") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when profile name is not provided -func Test_RunInternalConfig_NoProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile\. unable to determine new profile name$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when provided active profile name -func Test_RunInternalConfig_ActiveProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("default") - profileName = customtypes.String("test-profile") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. '.*' is the active profile and cannot be deleted$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} diff --git a/internal/configuration/config/add_profile.go b/internal/configuration/config/add_profile.go index 95026b60..d98d8f86 100644 --- a/internal/configuration/config/add_profile.go +++ b/internal/configuration/config/add_profile.go @@ -27,7 +27,6 @@ func initAddProfileDescriptionOption() { Shorthand: "d", Usage: "The description of the new configuration profile.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -49,7 +48,6 @@ func initAddProfileNameOption() { Shorthand: "n", Usage: "The name of the new configuration profile.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -69,9 +67,10 @@ func initAddProfileSetActiveOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: "Set the new configuration profile as the active profile.", - Value: cobraValue, - DefValue: "false", + Usage: "Set the new configuration profile as the active profile. " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "", // No viper key diff --git a/internal/configuration/config/config.go b/internal/configuration/config/config.go deleted file mode 100644 index bf134b1c..00000000 --- a/internal/configuration/config/config.go +++ /dev/null @@ -1,79 +0,0 @@ -package configuration_config - -import ( - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/customtypes" - "github.com/spf13/pflag" -) - -func InitConfigOptions() { - initConfigProfileOption() - initConfigNameOption() - initConfigDescriptionOption() -} - -func initConfigProfileOption() { - cobraParamName := "profile" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigProfileOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "p", - Usage: "The name of the profile to update. Example: `myAwesomeProfile`", - Value: cobraValue, - DefValue: "The active profile", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} - -func initConfigNameOption() { - cobraParamName := "name" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigNameOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "n", - Usage: "The new name for the profile.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} - -func initConfigDescriptionOption() { - cobraParamName := "description" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigDescriptionOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "d", - Usage: "The new description for the profile.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} diff --git a/internal/configuration/config/delete_profile.go b/internal/configuration/config/delete_profile.go index 6cbcf2bb..9c0d0a21 100644 --- a/internal/configuration/config/delete_profile.go +++ b/internal/configuration/config/delete_profile.go @@ -21,11 +21,11 @@ func initDeleteAutoAcceptOption() { DefaultValue: &defaultValue, EnvVar: "", // No environment variable Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "y", - Usage: "Auto-accept the profile deletion confirmation prompt.", + Name: cobraParamName, + Shorthand: "y", + Usage: "Auto-accept the profile deletion confirmation prompt. " + + "(default false)", Value: cobraValue, - DefValue: "false", NoOptDefVal: "true", // Make the flag a boolean flag }, Type: options.ENUM_STRING, diff --git a/internal/configuration/config/get.go b/internal/configuration/config/get.go index ffdfaa27..49ede6ef 100644 --- a/internal/configuration/config/get.go +++ b/internal/configuration/config/get.go @@ -23,9 +23,9 @@ func initGetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to get the configuration value from.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile used to get the configuration value from. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/set.go b/internal/configuration/config/set.go index 90dd99bf..722260c1 100644 --- a/internal/configuration/config/set.go +++ b/internal/configuration/config/set.go @@ -23,9 +23,9 @@ func initSetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to set the configuration value to.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile used to set the configuration value to. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/unset.go b/internal/configuration/config/unset.go index d8151c4c..08bcb27f 100644 --- a/internal/configuration/config/unset.go +++ b/internal/configuration/config/unset.go @@ -23,9 +23,9 @@ func initUnsetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile to unset a configuration value from.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile to unset a configuration value from. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index ff95b30d..cd46d877 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -81,7 +81,6 @@ func OptionFromViperKey(viperKey string) (opt options.Option, err error) { } func InitAllOptions() { - configuration_config.InitConfigOptions() configuration_config.InitConfigAddProfileOptions() configuration_config.InitConfigDeleteProfileOptions() configuration_config.InitConfigSetOptions() diff --git a/internal/configuration/options/options.go b/internal/configuration/options/options.go index 8addec9a..b19e10f5 100644 --- a/internal/configuration/options/options.go +++ b/internal/configuration/options/options.go @@ -67,9 +67,6 @@ func Options() []Option { ProfileDescriptionOption, - ConfigProfileOption, - ConfigNameOption, - ConfigDescriptionOption, ConfigAddProfileDescriptionOption, ConfigAddProfileNameOption, ConfigAddProfileSetActiveOption, @@ -114,10 +111,6 @@ var ( // 'pingcli config' command options var ( - ConfigProfileOption Option - ConfigNameOption Option - ConfigDescriptionOption Option - ConfigAddProfileDescriptionOption Option ConfigAddProfileNameOption Option ConfigAddProfileSetActiveOption Option diff --git a/internal/configuration/platform/export.go b/internal/configuration/platform/export.go index fb45e84b..2cfdc85e 100644 --- a/internal/configuration/platform/export.go +++ b/internal/configuration/platform/export.go @@ -33,9 +33,13 @@ func initFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "f", - Usage: fmt.Sprintf("Specifies the export format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.ExportFormatValidValues(), ", "), string(customtypes.ENUM_EXPORT_FORMAT_HCL)), - Value: cobraValue, - DefValue: customtypes.ENUM_EXPORT_FORMAT_HCL, + Usage: fmt.Sprintf( + "Specifies the export format. (default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_EXPORT_FORMAT_HCL, + strings.Join(customtypes.ExportFormatValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "export.format", @@ -56,9 +60,18 @@ func initServicesOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf("Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services.\nOptions are: %s.\nExample: `%s,%s,%s`", strings.Join(customtypes.ExportServicesValidValues(), ", "), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE)), - Value: cobraValue, - DefValue: strings.Join(customtypes.ExportServicesValidValues(), ", "), + Usage: fmt.Sprintf( + "Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services. "+ + "(default %s)"+ + "\nOptions are: %s."+ + "\nExample: `%s,%s,%s`", + strings.Join(customtypes.ExportServicesValidValues(), ", "), + strings.Join(customtypes.ExportServicesValidValues(), ", "), + string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), + string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), + string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE), + ), + Value: cobraValue, }, Type: options.ENUM_EXPORT_SERVICES, ViperKey: "export.services", @@ -79,9 +92,10 @@ func initOutputDirectoryOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "d", - Usage: "Specifies the output directory for export. Example: `$HOME/pingcli-export`", - Value: cobraValue, - DefValue: "$(pwd)/export", + Usage: "Specifies the output directory for export. " + + "(default $(pwd)/export)" + + "\nExample: `$HOME/pingcli-export`", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "export.outputDirectory", @@ -101,15 +115,37 @@ func initOverwriteOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "o", - Usage: "Overwrite the existing generated exports in output directory.", - Value: cobraValue, - DefValue: "false", + Usage: "Overwrite the existing generated exports in output directory. " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "export.overwrite", } } +func initPingOneEnvironmentIDOption() { + cobraParamName := "pingone-export-environment-id" + cobraValue := new(customtypes.UUID) + defaultValue := customtypes.UUID("") + envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" + + options.PlatformExportPingOneEnvironmentIDOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: envVar, + Flag: &pflag.Flag{ + Name: cobraParamName, + Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", + Value: cobraValue, + }, + Type: options.ENUM_UUID, + ViperKey: "export.pingone.environmentID", + } +} + func getDefaultExportDir() (defaultExportDir *customtypes.String) { l := logger.Get() pwd, err := os.Getwd() @@ -128,25 +164,3 @@ func getDefaultExportDir() (defaultExportDir *customtypes.String) { return defaultExportDir } - -func initPingOneEnvironmentIDOption() { - cobraParamName := "pingone-export-environment-id" - cobraValue := new(customtypes.UUID) - defaultValue := customtypes.UUID("") - envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" - - options.PlatformExportPingOneEnvironmentIDOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: envVar, - Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_UUID, - ViperKey: "export.pingone.environmentID", - } -} diff --git a/internal/configuration/request/request.go b/internal/configuration/request/request.go index 3d7d1e7b..49d2d5e8 100644 --- a/internal/configuration/request/request.go +++ b/internal/configuration/request/request.go @@ -30,10 +30,10 @@ func initDataOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. Example: `@data.json`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. " + + "\nExample: `@data.json`", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -53,9 +53,15 @@ func initHTTPMethodOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "m", - Usage: fmt.Sprintf("The HTTP method to use for the request.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.HTTPMethodValidValues(), ", "), string(customtypes.ENUM_HTTP_METHOD_POST)), - Value: cobraValue, - DefValue: customtypes.ENUM_HTTP_METHOD_GET, + Usage: fmt.Sprintf( + "The HTTP method to use for the request. (default %s)"+ + "\nOptions are: %s."+ + "\nExample: `%s`", + customtypes.ENUM_HTTP_METHOD_GET, + strings.Join(customtypes.HTTPMethodValidValues(), ", "), + customtypes.ENUM_HTTP_METHOD_POST, + ), + Value: cobraValue, }, Type: options.ENUM_REQUEST_HTTP_METHOD, ViperKey: "", // No viper key @@ -76,9 +82,14 @@ func initServiceOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf("The Ping service (configured in the active profile) to send the custom request to.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.RequestServiceValidValues(), ", "), string(customtypes.ENUM_REQUEST_SERVICE_PINGONE)), - Value: cobraValue, - DefValue: "", + Usage: fmt.Sprintf( + "The Ping service (configured in the active profile) to send the custom request to."+ + "\nOptions are: %s."+ + "\nExample: `%s`", + strings.Join(customtypes.RequestServiceValidValues(), ", "), + customtypes.ENUM_REQUEST_SERVICE_PINGONE, + ), + Value: cobraValue, }, Type: options.ENUM_REQUEST_SERVICE, ViperKey: "request.service", diff --git a/internal/configuration/root/root.go b/internal/configuration/root/root.go index c731e0de..bc7d770c 100644 --- a/internal/configuration/root/root.go +++ b/internal/configuration/root/root.go @@ -12,6 +12,7 @@ import ( ) func InitRootOptions() { + initActiveProfileOption() initProfileOption() initColorOption() @@ -48,7 +49,6 @@ func initProfileOption() { Shorthand: "P", Usage: "The name of a configuration profile to use.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -56,23 +56,23 @@ func initProfileOption() { } func initColorOption() { - cobraParamName := "color" + cobraParamName := "no-color" cobraValue := new(customtypes.Bool) - defaultValue := customtypes.Bool(true) + defaultValue := customtypes.Bool(false) options.RootColorOption = options.Option{ CobraParamName: cobraParamName, CobraParamValue: cobraValue, DefaultValue: &defaultValue, - EnvVar: "PINGCLI_COLOR", + EnvVar: "PINGCLI_NO_COLOR", Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Show text output in color.", - Value: cobraValue, - DefValue: "true", + Name: cobraParamName, + Usage: "Disable text output in color. (default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, - ViperKey: "color", + ViperKey: "noColor", } } @@ -89,9 +89,9 @@ func initConfigOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "C", - Usage: "The relative or full path to a custom Ping CLI configuration file. Example: `$HOME/.pingcli/config.yaml`", - Value: cobraValue, - DefValue: "\"$HOME/.pingcli/config.yaml\"", + Usage: "The relative or full path to a custom Ping CLI configuration file. " + + "(default $HOME/.pingcli/config.yaml)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -111,9 +111,14 @@ func initOutputFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "O", - Usage: fmt.Sprintf("Specify the console output format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.OutputFormatValidValues(), ", "), string(customtypes.ENUM_OUTPUT_FORMAT_JSON)), - Value: cobraValue, - DefValue: customtypes.ENUM_OUTPUT_FORMAT_TEXT, + Usage: fmt.Sprintf( + "Specify the console output format. "+ + "(default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_OUTPUT_FORMAT_TEXT, + strings.Join(customtypes.OutputFormatValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_OUTPUT_FORMAT, ViperKey: "outputFormat", diff --git a/internal/configuration/services/pingfederate.go b/internal/configuration/services/pingfederate.go index 5b439c1b..bcce899e 100644 --- a/internal/configuration/services/pingfederate.go +++ b/internal/configuration/services/pingfederate.go @@ -37,10 +37,10 @@ func initHTTPSHostOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API.\nExample: `https://pingfederate-admin.bxretail.org`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API." + + "\nExample: `https://pingfederate-admin.bxretail.org`", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.httpsHost", @@ -59,10 +59,10 @@ func initAdminAPIPathOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API.\nExample: `/pf-admin-api/v1`", - Value: cobraValue, - DefValue: "/pf-admin-api/v1", + Name: cobraParamName, + Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API. " + + "(default /pf-admin-api/v1)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.adminAPIPath", @@ -81,10 +81,12 @@ func initXBypassExternalValidationHeaderOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header when using PingFederate's admin API).", - Value: cobraValue, - DefValue: "false", + Name: cobraParamName, + Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header " + + "when using PingFederate's admin API). " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.xBypassExternalValidationHeader", @@ -103,10 +105,12 @@ func initCACertificatePemFilesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when connecting to the PingFederate server over HTTPS.\nAccepts a comma-separated string to delimit multiple PEM files.", - Value: cobraValue, - DefValue: "[]", + Name: cobraParamName, + Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when " + + "connecting to the PingFederate server over HTTPS. " + + "(default [])" + + "\nAccepts a comma-separated string to delimit multiple PEM files.", + Value: cobraValue, }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.caCertificatePemFiles", @@ -125,10 +129,12 @@ func initInsecureTrustAllTLSOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Trust any certificate when connecting to the PingFederate server admin API.\nThis is insecure and should not be enabled outside of testing.", - Value: cobraValue, - DefValue: "false", + Name: cobraParamName, + Usage: "Trust any certificate when connecting to the PingFederate server admin API. " + + "(default false)" + + "\nThis is insecure and should not be enabled outside of testing.", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.insecureTrustAllTLS", @@ -147,10 +153,11 @@ func initUsernameOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic authentication. Example: `administrator`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic " + + "authentication." + + "\nExample: `administrator`", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.username", @@ -169,10 +176,10 @@ func initPasswordOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic authentication.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic " + + "authentication.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.password", @@ -191,10 +198,10 @@ func initAccessTokenOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a custom OAuth 2.0 token method.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a " + + "custom OAuth 2.0 token method.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.accessTokenAuth.accessToken", @@ -213,10 +220,10 @@ func initClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientID", @@ -235,10 +242,10 @@ func initClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when " + + "using the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientSecret", @@ -257,10 +264,10 @@ func initTokenURLOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.tokenURL", @@ -279,10 +286,13 @@ func initScopesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.\nAccepts a comma-separated string to delimit multiple scopes.\nExample: `openid,profile`", - Value: cobraValue, - DefValue: "[]", + Name: cobraParamName, + Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type. " + + "(default [])" + + "\nAccepts a comma-separated string to delimit multiple scopes." + + "\nExample: `openid,profile`", + Value: cobraValue, }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.scopes", @@ -301,10 +311,15 @@ func initPingFederateAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The authentication type to use when connecting to the PingFederate admin API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC)), - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: fmt.Sprintf( + "The authentication type to use when connecting to the PingFederate admin API."+ + "\nOptions are: %s."+ + "\nExample: `%s`", + strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), + customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC, + ), + Value: cobraValue, }, Type: options.ENUM_PINGFEDERATE_AUTH_TYPE, ViperKey: "service.pingfederate.authentication.type", diff --git a/internal/configuration/services/pingone.go b/internal/configuration/services/pingone.go index 43367ba1..e6686d60 100644 --- a/internal/configuration/services/pingone.go +++ b/internal/configuration/services/pingone.go @@ -30,10 +30,9 @@ func initAuthenticationWorkerClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client ID used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The worker client ID used to authenticate to the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.clientID", @@ -52,10 +51,9 @@ func initAuthenticationWorkerClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client secret used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The worker client secret used to authenticate to the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingone.authentication.worker.clientSecret", @@ -74,10 +72,10 @@ func initAuthenticationWorkerEnvironmentIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to " + + "the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.environmentID", @@ -96,10 +94,14 @@ func initPingOneAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The authentication type to use to authenticate to the PingOne management API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER)), - Value: cobraValue, - DefValue: customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, + Name: cobraParamName, + Usage: fmt.Sprintf( + "The authentication type to use to authenticate to the PingOne management API. (default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, + strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_PINGONE_AUTH_TYPE, ViperKey: "service.pingone.authentication.type", @@ -118,10 +120,15 @@ func initRegionCodeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The region code of the PingOne tenant.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), string(customtypes.ENUM_PINGONE_REGION_CODE_NA)), - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: fmt.Sprintf( + "The region code of the PingOne tenant."+ + "\nOptions are: %s."+ + "\nExample: `%s`", + strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), + customtypes.ENUM_PINGONE_REGION_CODE_NA, + ), + Value: cobraValue, }, Type: options.ENUM_PINGONE_REGION_CODE, ViperKey: "service.pingone.regionCode", diff --git a/internal/output/output.go b/internal/output/output.go index 607258fb..0d5ec8ad 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -40,15 +40,15 @@ const ( ) func Print(output Opts) { - colorizeOutput, err := profiles.GetOptionValue(options.RootColorOption) + disableColorOutput, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { color.NoColor = false } else { - colorizeOutputBool, err := strconv.ParseBool(colorizeOutput) + disableColorOutputBool, err := strconv.ParseBool(disableColorOutput) if err != nil { color.NoColor = false } else { - color.NoColor = !colorizeOutputBool + color.NoColor = disableColorOutputBool } } From 10e8c8ef0c4b597f333b8616d504d2c74f54eedb Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Thu, 17 Oct 2024 20:10:30 +0200 Subject: [PATCH 3/3] Revert "PDI-2056: Add Defaults to Usage Output" This reverts commit 039444e31e7ffe1beefdb809dea74e3fa9b4b058. --- cmd/config/config.go | 25 ++++ internal/commands/config/config_internal.go | 111 +++++++++++++++ .../commands/config/config_internal_test.go | 132 ++++++++++++++++++ internal/configuration/config/add_profile.go | 9 +- internal/configuration/config/config.go | 79 +++++++++++ .../configuration/config/delete_profile.go | 8 +- internal/configuration/config/get.go | 6 +- internal/configuration/config/set.go | 6 +- internal/configuration/config/unset.go | 6 +- internal/configuration/configuration.go | 1 + internal/configuration/options/options.go | 7 + internal/configuration/platform/export.go | 82 +++++------ internal/configuration/request/request.go | 31 ++-- internal/configuration/root/root.go | 35 ++--- .../configuration/services/pingfederate.go | 119 +++++++--------- internal/configuration/services/pingone.go | 47 +++---- internal/output/output.go | 6 +- 17 files changed, 507 insertions(+), 203 deletions(-) create mode 100644 internal/commands/config/config_internal.go create mode 100644 internal/commands/config/config_internal_test.go create mode 100644 internal/configuration/config/config.go diff --git a/cmd/config/config.go b/cmd/config/config.go index 98182cca..2811adf7 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -4,11 +4,21 @@ import ( "github.com/spf13/cobra" ) +// const ( +// configCommandExamples = ` pingcli config +// pingcli config --profile myprofile +// pingcli config --name myprofile --description "My Profile"` +// ) + func NewConfigCommand() *cobra.Command { cmd := &cobra.Command{ + // Args: common.ExactArgs(0), + // DisableFlagsInUseLine: true, // We write our own flags in @Use attribute + // Example: configCommandExamples, Long: "Manage the configuration of the CLI, including Ping product connection parameters.\n\n" + "The Ping CLI supports the use of configuration profiles.\nConfiguration profiles can be used when connecting to multiple environments using the same Ping CLI instance, such as when managing multiple development or demonstration environments.\n\n" + "A pre-defined default profile will be used to store the configuration of the CLI.\nAdditional custom profiles can be created using the `pingcli config add-profile` command.\nTo use a custom profile, the `--profile` flag can be used on supported commands to specify the profile to use for that command.\nTo set a custom profile as the default, use the `pingcli config set-active-profile` command.", + // RunE: configRunE, Short: "Manage the CLI configuration.", Use: "config", } @@ -25,5 +35,20 @@ func NewConfigCommand() *cobra.Command { NewConfigUnsetCommand(), ) + // cmd.Flags().AddFlag(options.ConfigProfileOption.Flag) + // cmd.Flags().AddFlag(options.ConfigNameOption.Flag) + // cmd.Flags().AddFlag(options.ConfigDescriptionOption.Flag) + return cmd } + +// func configRunE(cmd *cobra.Command, args []string) error { +// l := logger.Get() +// l.Debug().Msgf("Config Subcommand Called.") + +// if err := config_internal.RunInternalConfig(os.Stdin); err != nil { +// return err +// } + +// return nil +// } diff --git a/internal/commands/config/config_internal.go b/internal/commands/config/config_internal.go new file mode 100644 index 00000000..9d7bf2f2 --- /dev/null +++ b/internal/commands/config/config_internal.go @@ -0,0 +1,111 @@ +package config_internal + +import ( + "fmt" + "io" + + "github.com/pingidentity/pingcli/internal/configuration/options" + "github.com/pingidentity/pingcli/internal/input" + "github.com/pingidentity/pingcli/internal/output" + "github.com/pingidentity/pingcli/internal/profiles" +) + +func RunInternalConfig(rc io.ReadCloser) (err error) { + profileName, newProfileName, newDescription, err := readConfigOptions(rc) + if err != nil { + return fmt.Errorf("failed to update profile. %v", err) + } + + output.Print(output.Opts{ + Message: fmt.Sprintf("Updating profile '%s'...", profileName), + Result: output.ENUM_RESULT_NIL, + }) + + if err = profiles.GetMainConfig().ChangeProfileName(profileName, newProfileName); err != nil { + return fmt.Errorf("failed to update profile '%s' name to: %s. %v", profileName, newProfileName, err) + } + + if err = profiles.GetMainConfig().ChangeProfileDescription(newProfileName, newDescription); err != nil { + return fmt.Errorf("failed to update profile '%s' description to: %s. %v", newProfileName, newDescription, err) + } + + output.Print(output.Opts{ + Message: fmt.Sprintf("Profile updated. Update additional profile attributes via 'pingcli config set' or directly within the config file at '%s'", profiles.GetMainConfig().ViperInstance().ConfigFileUsed()), + Result: output.ENUM_RESULT_SUCCESS, + }) + + return nil +} + +func readConfigOptions(rc io.ReadCloser) (profileName, newName, description string, err error) { + if profileName, err = readConfigProfileNameOption(); err != nil { + return profileName, newName, description, err + } + + if newName, err = readConfigNameOption(rc); err != nil { + return profileName, newName, description, err + } + + if description, err = readConfigDescriptionOption(rc); err != nil { + return profileName, newName, description, err + } + + return profileName, newName, description, nil +} + +func readConfigProfileNameOption() (pName string, err error) { + if !options.ConfigProfileOption.Flag.Changed { + pName, err = profiles.GetOptionValue(options.RootActiveProfileOption) + } else { + pName, err = profiles.GetOptionValue(options.ConfigProfileOption) + } + + if err != nil { + return pName, err + } + + if pName == "" { + return pName, fmt.Errorf("unable to determine profile name to update") + } + + return pName, nil +} + +func readConfigNameOption(rc io.ReadCloser) (newName string, err error) { + if !options.ConfigNameOption.Flag.Changed { + newName, err = input.RunPrompt("New profile name: ", validateChangeProfileName, rc) + } else { + newName, err = profiles.GetOptionValue(options.ConfigNameOption) + } + + if err != nil { + return newName, err + } + + if newName == "" { + return newName, fmt.Errorf("unable to determine new profile name") + } + + return newName, nil +} + +func readConfigDescriptionOption(rc io.ReadCloser) (description string, err error) { + if !options.ConfigDescriptionOption.Flag.Changed { + return input.RunPrompt("New profile description: ", nil, rc) + } else { + return profiles.GetOptionValue(options.ConfigDescriptionOption) + } +} + +func validateChangeProfileName(newName string) (err error) { + oldName, err := readConfigProfileNameOption() + if err != nil { + return err + } + + if err = profiles.GetMainConfig().ValidateUpdateExistingProfileName(oldName, newName); err != nil { + return err + } + + return nil +} diff --git a/internal/commands/config/config_internal_test.go b/internal/commands/config/config_internal_test.go new file mode 100644 index 00000000..f768746e --- /dev/null +++ b/internal/commands/config/config_internal_test.go @@ -0,0 +1,132 @@ +package config_internal + +import ( + "os" + "testing" + + "github.com/pingidentity/pingcli/internal/configuration/options" + "github.com/pingidentity/pingcli/internal/customtypes" + "github.com/pingidentity/pingcli/internal/testing/testutils" + "github.com/pingidentity/pingcli/internal/testing/testutils_viper" +) + +// Test RunInternalConfig function +func Test_RunInternalConfig(t *testing.T) { + testutils_viper.InitVipers(t) + + var ( + oldProfile = customtypes.String("production") + profileName = customtypes.String("test-profile") + description = customtypes.String("test-description") + ) + + options.ConfigProfileOption.Flag.Changed = true + options.ConfigProfileOption.CobraParamValue = &oldProfile + + options.ConfigNameOption.Flag.Changed = true + options.ConfigNameOption.CobraParamValue = &profileName + + options.ConfigDescriptionOption.Flag.Changed = true + options.ConfigDescriptionOption.CobraParamValue = &description + + err := RunInternalConfig(os.Stdin) + if err != nil { + t.Errorf("RunInternalConfig returned error: %v", err) + } +} + +// Test RunInternalConfig function fails when existing profile name is provided +func Test_RunInternalConfig_ExistingProfileName(t *testing.T) { + testutils_viper.InitVipers(t) + + var ( + oldProfile = customtypes.String("production") + profileName = customtypes.String("default") + description = customtypes.String("test-description") + ) + + options.ConfigProfileOption.Flag.Changed = true + options.ConfigProfileOption.CobraParamValue = &oldProfile + + options.ConfigNameOption.Flag.Changed = true + options.ConfigNameOption.CobraParamValue = &profileName + + options.ConfigDescriptionOption.Flag.Changed = true + options.ConfigDescriptionOption.CobraParamValue = &description + + expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. profile already exists$` + err := RunInternalConfig(os.Stdin) + testutils.CheckExpectedError(t, err, &expectedErrorPattern) +} + +// Test RunInternalConfig function fails when invalid profile name is provided +func Test_RunInternalConfig_InvalidProfileName(t *testing.T) { + testutils_viper.InitVipers(t) + + var ( + oldProfile = customtypes.String("production") + profileName = customtypes.String("test-profile!") + description = customtypes.String("test-description") + ) + + options.ConfigProfileOption.Flag.Changed = true + options.ConfigProfileOption.CobraParamValue = &oldProfile + + options.ConfigNameOption.Flag.Changed = true + options.ConfigNameOption.CobraParamValue = &profileName + + options.ConfigDescriptionOption.Flag.Changed = true + options.ConfigDescriptionOption.CobraParamValue = &description + + expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$` + err := RunInternalConfig(os.Stdin) + testutils.CheckExpectedError(t, err, &expectedErrorPattern) +} + +// Test RunInternalConfig function fails when profile name is not provided +func Test_RunInternalConfig_NoProfileName(t *testing.T) { + testutils_viper.InitVipers(t) + + var ( + oldProfile = customtypes.String("production") + profileName = customtypes.String("") + description = customtypes.String("test-description") + ) + + options.ConfigProfileOption.Flag.Changed = true + options.ConfigProfileOption.CobraParamValue = &oldProfile + + options.ConfigNameOption.Flag.Changed = true + options.ConfigNameOption.CobraParamValue = &profileName + + options.ConfigDescriptionOption.Flag.Changed = true + options.ConfigDescriptionOption.CobraParamValue = &description + + expectedErrorPattern := `^failed to update profile\. unable to determine new profile name$` + err := RunInternalConfig(os.Stdin) + testutils.CheckExpectedError(t, err, &expectedErrorPattern) +} + +// Test RunInternalConfig function fails when provided active profile name +func Test_RunInternalConfig_ActiveProfileName(t *testing.T) { + testutils_viper.InitVipers(t) + + var ( + oldProfile = customtypes.String("default") + profileName = customtypes.String("test-profile") + description = customtypes.String("test-description") + ) + + options.ConfigProfileOption.Flag.Changed = true + options.ConfigProfileOption.CobraParamValue = &oldProfile + + options.ConfigNameOption.Flag.Changed = true + options.ConfigNameOption.CobraParamValue = &profileName + + options.ConfigDescriptionOption.Flag.Changed = true + options.ConfigDescriptionOption.CobraParamValue = &description + + expectedErrorPattern := `^failed to update profile '.*' name to: .*\. '.*' is the active profile and cannot be deleted$` + err := RunInternalConfig(os.Stdin) + testutils.CheckExpectedError(t, err, &expectedErrorPattern) +} diff --git a/internal/configuration/config/add_profile.go b/internal/configuration/config/add_profile.go index d98d8f86..95026b60 100644 --- a/internal/configuration/config/add_profile.go +++ b/internal/configuration/config/add_profile.go @@ -27,6 +27,7 @@ func initAddProfileDescriptionOption() { Shorthand: "d", Usage: "The description of the new configuration profile.", Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -48,6 +49,7 @@ func initAddProfileNameOption() { Shorthand: "n", Usage: "The name of the new configuration profile.", Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -67,10 +69,9 @@ func initAddProfileSetActiveOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: "Set the new configuration profile as the active profile. " + - "(default false)", - Value: cobraValue, - NoOptDefVal: "true", // Make this flag a boolean flag + Usage: "Set the new configuration profile as the active profile.", + Value: cobraValue, + DefValue: "false", }, Type: options.ENUM_BOOL, ViperKey: "", // No viper key diff --git a/internal/configuration/config/config.go b/internal/configuration/config/config.go new file mode 100644 index 00000000..bf134b1c --- /dev/null +++ b/internal/configuration/config/config.go @@ -0,0 +1,79 @@ +package configuration_config + +import ( + "github.com/pingidentity/pingcli/internal/configuration/options" + "github.com/pingidentity/pingcli/internal/customtypes" + "github.com/spf13/pflag" +) + +func InitConfigOptions() { + initConfigProfileOption() + initConfigNameOption() + initConfigDescriptionOption() +} + +func initConfigProfileOption() { + cobraParamName := "profile" + cobraValue := new(customtypes.String) + defaultValue := customtypes.String("") + + options.ConfigProfileOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: "", // No environment variable + Flag: &pflag.Flag{ + Name: cobraParamName, + Shorthand: "p", + Usage: "The name of the profile to update. Example: `myAwesomeProfile`", + Value: cobraValue, + DefValue: "The active profile", + }, + Type: options.ENUM_STRING, + ViperKey: "", // No viper key + } +} + +func initConfigNameOption() { + cobraParamName := "name" + cobraValue := new(customtypes.String) + defaultValue := customtypes.String("") + + options.ConfigNameOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: "", // No environment variable + Flag: &pflag.Flag{ + Name: cobraParamName, + Shorthand: "n", + Usage: "The new name for the profile.", + Value: cobraValue, + DefValue: "", + }, + Type: options.ENUM_STRING, + ViperKey: "", // No viper key + } +} + +func initConfigDescriptionOption() { + cobraParamName := "description" + cobraValue := new(customtypes.String) + defaultValue := customtypes.String("") + + options.ConfigDescriptionOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: "", // No environment variable + Flag: &pflag.Flag{ + Name: cobraParamName, + Shorthand: "d", + Usage: "The new description for the profile.", + Value: cobraValue, + DefValue: "", + }, + Type: options.ENUM_STRING, + ViperKey: "", // No viper key + } +} diff --git a/internal/configuration/config/delete_profile.go b/internal/configuration/config/delete_profile.go index 9c0d0a21..6cbcf2bb 100644 --- a/internal/configuration/config/delete_profile.go +++ b/internal/configuration/config/delete_profile.go @@ -21,11 +21,11 @@ func initDeleteAutoAcceptOption() { DefaultValue: &defaultValue, EnvVar: "", // No environment variable Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "y", - Usage: "Auto-accept the profile deletion confirmation prompt. " + - "(default false)", + Name: cobraParamName, + Shorthand: "y", + Usage: "Auto-accept the profile deletion confirmation prompt.", Value: cobraValue, + DefValue: "false", NoOptDefVal: "true", // Make the flag a boolean flag }, Type: options.ENUM_STRING, diff --git a/internal/configuration/config/get.go b/internal/configuration/config/get.go index 49ede6ef..ffdfaa27 100644 --- a/internal/configuration/config/get.go +++ b/internal/configuration/config/get.go @@ -23,9 +23,9 @@ func initGetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to get the configuration value from. " + - "(default The active profile)", - Value: cobraValue, + Usage: "The name of the configuration profile used to get the configuration value from.", + Value: cobraValue, + DefValue: "The active profile", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/set.go b/internal/configuration/config/set.go index 722260c1..90dd99bf 100644 --- a/internal/configuration/config/set.go +++ b/internal/configuration/config/set.go @@ -23,9 +23,9 @@ func initSetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to set the configuration value to. " + - "(default The active profile)", - Value: cobraValue, + Usage: "The name of the configuration profile used to set the configuration value to.", + Value: cobraValue, + DefValue: "The active profile", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/unset.go b/internal/configuration/config/unset.go index 08bcb27f..d8151c4c 100644 --- a/internal/configuration/config/unset.go +++ b/internal/configuration/config/unset.go @@ -23,9 +23,9 @@ func initUnsetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile to unset a configuration value from. " + - "(default The active profile)", - Value: cobraValue, + Usage: "The name of the configuration profile to unset a configuration value from.", + Value: cobraValue, + DefValue: "The active profile", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index cd46d877..ff95b30d 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -81,6 +81,7 @@ func OptionFromViperKey(viperKey string) (opt options.Option, err error) { } func InitAllOptions() { + configuration_config.InitConfigOptions() configuration_config.InitConfigAddProfileOptions() configuration_config.InitConfigDeleteProfileOptions() configuration_config.InitConfigSetOptions() diff --git a/internal/configuration/options/options.go b/internal/configuration/options/options.go index b19e10f5..8addec9a 100644 --- a/internal/configuration/options/options.go +++ b/internal/configuration/options/options.go @@ -67,6 +67,9 @@ func Options() []Option { ProfileDescriptionOption, + ConfigProfileOption, + ConfigNameOption, + ConfigDescriptionOption, ConfigAddProfileDescriptionOption, ConfigAddProfileNameOption, ConfigAddProfileSetActiveOption, @@ -111,6 +114,10 @@ var ( // 'pingcli config' command options var ( + ConfigProfileOption Option + ConfigNameOption Option + ConfigDescriptionOption Option + ConfigAddProfileDescriptionOption Option ConfigAddProfileNameOption Option ConfigAddProfileSetActiveOption Option diff --git a/internal/configuration/platform/export.go b/internal/configuration/platform/export.go index 2cfdc85e..fb45e84b 100644 --- a/internal/configuration/platform/export.go +++ b/internal/configuration/platform/export.go @@ -33,13 +33,9 @@ func initFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "f", - Usage: fmt.Sprintf( - "Specifies the export format. (default %s)"+ - "\nOptions are: %s.", - customtypes.ENUM_EXPORT_FORMAT_HCL, - strings.Join(customtypes.ExportFormatValidValues(), ", "), - ), - Value: cobraValue, + Usage: fmt.Sprintf("Specifies the export format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.ExportFormatValidValues(), ", "), string(customtypes.ENUM_EXPORT_FORMAT_HCL)), + Value: cobraValue, + DefValue: customtypes.ENUM_EXPORT_FORMAT_HCL, }, Type: options.ENUM_STRING, ViperKey: "export.format", @@ -60,18 +56,9 @@ func initServicesOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf( - "Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services. "+ - "(default %s)"+ - "\nOptions are: %s."+ - "\nExample: `%s,%s,%s`", - strings.Join(customtypes.ExportServicesValidValues(), ", "), - strings.Join(customtypes.ExportServicesValidValues(), ", "), - string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), - string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), - string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE), - ), - Value: cobraValue, + Usage: fmt.Sprintf("Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services.\nOptions are: %s.\nExample: `%s,%s,%s`", strings.Join(customtypes.ExportServicesValidValues(), ", "), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE)), + Value: cobraValue, + DefValue: strings.Join(customtypes.ExportServicesValidValues(), ", "), }, Type: options.ENUM_EXPORT_SERVICES, ViperKey: "export.services", @@ -92,10 +79,9 @@ func initOutputDirectoryOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "d", - Usage: "Specifies the output directory for export. " + - "(default $(pwd)/export)" + - "\nExample: `$HOME/pingcli-export`", - Value: cobraValue, + Usage: "Specifies the output directory for export. Example: `$HOME/pingcli-export`", + Value: cobraValue, + DefValue: "$(pwd)/export", }, Type: options.ENUM_STRING, ViperKey: "export.outputDirectory", @@ -115,37 +101,15 @@ func initOverwriteOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "o", - Usage: "Overwrite the existing generated exports in output directory. " + - "(default false)", - Value: cobraValue, - NoOptDefVal: "true", // Make this flag a boolean flag + Usage: "Overwrite the existing generated exports in output directory.", + Value: cobraValue, + DefValue: "false", }, Type: options.ENUM_BOOL, ViperKey: "export.overwrite", } } -func initPingOneEnvironmentIDOption() { - cobraParamName := "pingone-export-environment-id" - cobraValue := new(customtypes.UUID) - defaultValue := customtypes.UUID("") - envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" - - options.PlatformExportPingOneEnvironmentIDOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: envVar, - Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", - Value: cobraValue, - }, - Type: options.ENUM_UUID, - ViperKey: "export.pingone.environmentID", - } -} - func getDefaultExportDir() (defaultExportDir *customtypes.String) { l := logger.Get() pwd, err := os.Getwd() @@ -164,3 +128,25 @@ func getDefaultExportDir() (defaultExportDir *customtypes.String) { return defaultExportDir } + +func initPingOneEnvironmentIDOption() { + cobraParamName := "pingone-export-environment-id" + cobraValue := new(customtypes.UUID) + defaultValue := customtypes.UUID("") + envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" + + options.PlatformExportPingOneEnvironmentIDOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: envVar, + Flag: &pflag.Flag{ + Name: cobraParamName, + Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", + Value: cobraValue, + DefValue: "", + }, + Type: options.ENUM_UUID, + ViperKey: "export.pingone.environmentID", + } +} diff --git a/internal/configuration/request/request.go b/internal/configuration/request/request.go index 49d2d5e8..3d7d1e7b 100644 --- a/internal/configuration/request/request.go +++ b/internal/configuration/request/request.go @@ -30,10 +30,10 @@ func initDataOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. " + - "\nExample: `@data.json`", - Value: cobraValue, + Name: cobraParamName, + Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. Example: `@data.json`", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -53,15 +53,9 @@ func initHTTPMethodOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "m", - Usage: fmt.Sprintf( - "The HTTP method to use for the request. (default %s)"+ - "\nOptions are: %s."+ - "\nExample: `%s`", - customtypes.ENUM_HTTP_METHOD_GET, - strings.Join(customtypes.HTTPMethodValidValues(), ", "), - customtypes.ENUM_HTTP_METHOD_POST, - ), - Value: cobraValue, + Usage: fmt.Sprintf("The HTTP method to use for the request.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.HTTPMethodValidValues(), ", "), string(customtypes.ENUM_HTTP_METHOD_POST)), + Value: cobraValue, + DefValue: customtypes.ENUM_HTTP_METHOD_GET, }, Type: options.ENUM_REQUEST_HTTP_METHOD, ViperKey: "", // No viper key @@ -82,14 +76,9 @@ func initServiceOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf( - "The Ping service (configured in the active profile) to send the custom request to."+ - "\nOptions are: %s."+ - "\nExample: `%s`", - strings.Join(customtypes.RequestServiceValidValues(), ", "), - customtypes.ENUM_REQUEST_SERVICE_PINGONE, - ), - Value: cobraValue, + Usage: fmt.Sprintf("The Ping service (configured in the active profile) to send the custom request to.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.RequestServiceValidValues(), ", "), string(customtypes.ENUM_REQUEST_SERVICE_PINGONE)), + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_REQUEST_SERVICE, ViperKey: "request.service", diff --git a/internal/configuration/root/root.go b/internal/configuration/root/root.go index bc7d770c..c731e0de 100644 --- a/internal/configuration/root/root.go +++ b/internal/configuration/root/root.go @@ -12,7 +12,6 @@ import ( ) func InitRootOptions() { - initActiveProfileOption() initProfileOption() initColorOption() @@ -49,6 +48,7 @@ func initProfileOption() { Shorthand: "P", Usage: "The name of a configuration profile to use.", Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -56,23 +56,23 @@ func initProfileOption() { } func initColorOption() { - cobraParamName := "no-color" + cobraParamName := "color" cobraValue := new(customtypes.Bool) - defaultValue := customtypes.Bool(false) + defaultValue := customtypes.Bool(true) options.RootColorOption = options.Option{ CobraParamName: cobraParamName, CobraParamValue: cobraValue, DefaultValue: &defaultValue, - EnvVar: "PINGCLI_NO_COLOR", + EnvVar: "PINGCLI_COLOR", Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Disable text output in color. (default false)", - Value: cobraValue, - NoOptDefVal: "true", // Make this flag a boolean flag + Name: cobraParamName, + Usage: "Show text output in color.", + Value: cobraValue, + DefValue: "true", }, Type: options.ENUM_BOOL, - ViperKey: "noColor", + ViperKey: "color", } } @@ -89,9 +89,9 @@ func initConfigOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "C", - Usage: "The relative or full path to a custom Ping CLI configuration file. " + - "(default $HOME/.pingcli/config.yaml)", - Value: cobraValue, + Usage: "The relative or full path to a custom Ping CLI configuration file. Example: `$HOME/.pingcli/config.yaml`", + Value: cobraValue, + DefValue: "\"$HOME/.pingcli/config.yaml\"", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -111,14 +111,9 @@ func initOutputFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "O", - Usage: fmt.Sprintf( - "Specify the console output format. "+ - "(default %s)"+ - "\nOptions are: %s.", - customtypes.ENUM_OUTPUT_FORMAT_TEXT, - strings.Join(customtypes.OutputFormatValidValues(), ", "), - ), - Value: cobraValue, + Usage: fmt.Sprintf("Specify the console output format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.OutputFormatValidValues(), ", "), string(customtypes.ENUM_OUTPUT_FORMAT_JSON)), + Value: cobraValue, + DefValue: customtypes.ENUM_OUTPUT_FORMAT_TEXT, }, Type: options.ENUM_OUTPUT_FORMAT, ViperKey: "outputFormat", diff --git a/internal/configuration/services/pingfederate.go b/internal/configuration/services/pingfederate.go index bcce899e..5b439c1b 100644 --- a/internal/configuration/services/pingfederate.go +++ b/internal/configuration/services/pingfederate.go @@ -37,10 +37,10 @@ func initHTTPSHostOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API." + - "\nExample: `https://pingfederate-admin.bxretail.org`", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API.\nExample: `https://pingfederate-admin.bxretail.org`", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.httpsHost", @@ -59,10 +59,10 @@ func initAdminAPIPathOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API. " + - "(default /pf-admin-api/v1)", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API.\nExample: `/pf-admin-api/v1`", + Value: cobraValue, + DefValue: "/pf-admin-api/v1", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.adminAPIPath", @@ -81,12 +81,10 @@ func initXBypassExternalValidationHeaderOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header " + - "when using PingFederate's admin API). " + - "(default false)", - Value: cobraValue, - NoOptDefVal: "true", // Make this flag a boolean flag + Name: cobraParamName, + Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header when using PingFederate's admin API).", + Value: cobraValue, + DefValue: "false", }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.xBypassExternalValidationHeader", @@ -105,12 +103,10 @@ func initCACertificatePemFilesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when " + - "connecting to the PingFederate server over HTTPS. " + - "(default [])" + - "\nAccepts a comma-separated string to delimit multiple PEM files.", - Value: cobraValue, + Name: cobraParamName, + Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when connecting to the PingFederate server over HTTPS.\nAccepts a comma-separated string to delimit multiple PEM files.", + Value: cobraValue, + DefValue: "[]", }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.caCertificatePemFiles", @@ -129,12 +125,10 @@ func initInsecureTrustAllTLSOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Trust any certificate when connecting to the PingFederate server admin API. " + - "(default false)" + - "\nThis is insecure and should not be enabled outside of testing.", - Value: cobraValue, - NoOptDefVal: "true", // Make this flag a boolean flag + Name: cobraParamName, + Usage: "Trust any certificate when connecting to the PingFederate server admin API.\nThis is insecure and should not be enabled outside of testing.", + Value: cobraValue, + DefValue: "false", }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.insecureTrustAllTLS", @@ -153,11 +147,10 @@ func initUsernameOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic " + - "authentication." + - "\nExample: `administrator`", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic authentication. Example: `administrator`", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.username", @@ -176,10 +169,10 @@ func initPasswordOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic " + - "authentication.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic authentication.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.password", @@ -198,10 +191,10 @@ func initAccessTokenOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a " + - "custom OAuth 2.0 token method.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a custom OAuth 2.0 token method.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.accessTokenAuth.accessToken", @@ -220,10 +213,10 @@ func initClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using " + - "the OAuth 2.0 client credentials grant type.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientID", @@ -242,10 +235,10 @@ func initClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when " + - "using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientSecret", @@ -264,10 +257,10 @@ func initTokenURLOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using " + - "the OAuth 2.0 client credentials grant type.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.tokenURL", @@ -286,13 +279,10 @@ func initScopesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using " + - "the OAuth 2.0 client credentials grant type. " + - "(default [])" + - "\nAccepts a comma-separated string to delimit multiple scopes." + - "\nExample: `openid,profile`", - Value: cobraValue, + Name: cobraParamName, + Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.\nAccepts a comma-separated string to delimit multiple scopes.\nExample: `openid,profile`", + Value: cobraValue, + DefValue: "[]", }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.scopes", @@ -311,15 +301,10 @@ func initPingFederateAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf( - "The authentication type to use when connecting to the PingFederate admin API."+ - "\nOptions are: %s."+ - "\nExample: `%s`", - strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), - customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC, - ), - Value: cobraValue, + Name: cobraParamName, + Usage: fmt.Sprintf("The authentication type to use when connecting to the PingFederate admin API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC)), + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_PINGFEDERATE_AUTH_TYPE, ViperKey: "service.pingfederate.authentication.type", diff --git a/internal/configuration/services/pingone.go b/internal/configuration/services/pingone.go index e6686d60..43367ba1 100644 --- a/internal/configuration/services/pingone.go +++ b/internal/configuration/services/pingone.go @@ -30,9 +30,10 @@ func initAuthenticationWorkerClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client ID used to authenticate to the PingOne management API.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The worker client ID used to authenticate to the PingOne management API.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.clientID", @@ -51,9 +52,10 @@ func initAuthenticationWorkerClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client secret used to authenticate to the PingOne management API.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The worker client secret used to authenticate to the PingOne management API.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "service.pingone.authentication.worker.clientSecret", @@ -72,10 +74,10 @@ func initAuthenticationWorkerEnvironmentIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to " + - "the PingOne management API.", - Value: cobraValue, + Name: cobraParamName, + Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to the PingOne management API.", + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.environmentID", @@ -94,14 +96,10 @@ func initPingOneAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf( - "The authentication type to use to authenticate to the PingOne management API. (default %s)"+ - "\nOptions are: %s.", - customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, - strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), - ), - Value: cobraValue, + Name: cobraParamName, + Usage: fmt.Sprintf("The authentication type to use to authenticate to the PingOne management API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER)), + Value: cobraValue, + DefValue: customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, }, Type: options.ENUM_PINGONE_AUTH_TYPE, ViperKey: "service.pingone.authentication.type", @@ -120,15 +118,10 @@ func initRegionCodeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf( - "The region code of the PingOne tenant."+ - "\nOptions are: %s."+ - "\nExample: `%s`", - strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), - customtypes.ENUM_PINGONE_REGION_CODE_NA, - ), - Value: cobraValue, + Name: cobraParamName, + Usage: fmt.Sprintf("The region code of the PingOne tenant.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), string(customtypes.ENUM_PINGONE_REGION_CODE_NA)), + Value: cobraValue, + DefValue: "", }, Type: options.ENUM_PINGONE_REGION_CODE, ViperKey: "service.pingone.regionCode", diff --git a/internal/output/output.go b/internal/output/output.go index 0d5ec8ad..607258fb 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -40,15 +40,15 @@ const ( ) func Print(output Opts) { - disableColorOutput, err := profiles.GetOptionValue(options.RootColorOption) + colorizeOutput, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { color.NoColor = false } else { - disableColorOutputBool, err := strconv.ParseBool(disableColorOutput) + colorizeOutputBool, err := strconv.ParseBool(colorizeOutput) if err != nil { color.NoColor = false } else { - color.NoColor = disableColorOutputBool + color.NoColor = !colorizeOutputBool } }