diff --git a/internal/cmd/config/unset/unset.go b/internal/cmd/config/unset/unset.go index ac9e63a64..ff4e4d665 100644 --- a/internal/cmd/config/unset/unset.go +++ b/internal/cmd/config/unset/unset.go @@ -17,6 +17,7 @@ const ( asyncFlag = globalflags.AsyncFlag outputFormatFlag = globalflags.OutputFormatFlag projectIdFlag = globalflags.ProjectIdFlag + verbosityFlag = globalflags.VerbosityFlag sessionTimeLimitFlag = "session-time-limit" @@ -38,11 +39,11 @@ const ( ) type inputModel struct { - AsyncFlag bool - OutputFormat bool - ProjectId bool - + Async bool + OutputFormat bool + ProjectId bool SessionTimeLimit bool + Verbosity bool ArgusCustomEndpoint bool AuthorizationCustomEndpoint bool @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { model := parseInput(cmd) - if model.AsyncFlag { + if model.Async { viper.Set(config.AsyncKey, config.AsyncDefault) } if model.OutputFormat { @@ -90,10 +91,12 @@ func NewCmd() *cobra.Command { if model.ProjectId { viper.Set(config.ProjectIdKey, "") } - if model.SessionTimeLimit { viper.Set(config.SessionTimeLimitKey, config.SessionTimeLimitDefault) } + if model.Verbosity { + viper.Set(config.VerbosityKey, globalflags.VerbosityDefault) + } if model.ArgusCustomEndpoint { viper.Set(config.ArgusCustomEndpointKey, "") @@ -156,8 +159,8 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().Bool(asyncFlag, false, "Configuration option to run commands asynchronously") cmd.Flags().Bool(projectIdFlag, false, "Project ID") cmd.Flags().Bool(outputFormatFlag, false, "Output format") - cmd.Flags().Bool(sessionTimeLimitFlag, false, fmt.Sprintf("Maximum time before authentication is required again. If unset, defaults to %s", config.SessionTimeLimitDefault)) + cmd.Flags().Bool(verbosityFlag, false, "Verbosity of the CLI") cmd.Flags().Bool(argusCustomEndpointFlag, false, "Argus API base URL. If unset, uses the default base URL") cmd.Flags().Bool(authorizationCustomEndpointFlag, false, "Authorization API base URL. If unset, uses the default base URL") @@ -178,11 +181,12 @@ func configureFlags(cmd *cobra.Command) { func parseInput(cmd *cobra.Command) *inputModel { return &inputModel{ - AsyncFlag: flags.FlagToBoolValue(cmd, asyncFlag), - OutputFormat: flags.FlagToBoolValue(cmd, outputFormatFlag), - ProjectId: flags.FlagToBoolValue(cmd, projectIdFlag), + Async: flags.FlagToBoolValue(cmd, asyncFlag), + OutputFormat: flags.FlagToBoolValue(cmd, outputFormatFlag), + ProjectId: flags.FlagToBoolValue(cmd, projectIdFlag), + SessionTimeLimit: flags.FlagToBoolValue(cmd, sessionTimeLimitFlag), + Verbosity: flags.FlagToBoolValue(cmd, verbosityFlag), - SessionTimeLimit: flags.FlagToBoolValue(cmd, sessionTimeLimitFlag), ArgusCustomEndpoint: flags.FlagToBoolValue(cmd, argusCustomEndpointFlag), AuthorizationCustomEndpoint: flags.FlagToBoolValue(cmd, authorizationCustomEndpointFlag), DNSCustomEndpoint: flags.FlagToBoolValue(cmd, dnsCustomEndpointFlag), diff --git a/internal/cmd/config/unset/unset_test.go b/internal/cmd/config/unset/unset_test.go index f68717953..738bbbdb5 100644 --- a/internal/cmd/config/unset/unset_test.go +++ b/internal/cmd/config/unset/unset_test.go @@ -9,8 +9,11 @@ import ( func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool { flagValues := map[string]bool{ - projectIdFlag: true, - outputFormatFlag: true, + asyncFlag: true, + outputFormatFlag: true, + projectIdFlag: true, + sessionTimeLimitFlag: true, + verbosityFlag: true, argusCustomEndpointFlag: true, authorizationCustomEndpointFlag: true, @@ -34,8 +37,11 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - ProjectId: true, - OutputFormat: true, + Async: true, + OutputFormat: true, + ProjectId: true, + SessionTimeLimit: true, + Verbosity: true, ArgusCustomEndpoint: true, AuthorizationCustomEndpoint: true, @@ -75,8 +81,11 @@ func TestParseInput(t *testing.T) { flagValues: map[string]bool{}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.ProjectId = false + model.Async = false model.OutputFormat = false + model.ProjectId = false + model.SessionTimeLimit = false + model.Verbosity = false model.ArgusCustomEndpoint = false model.AuthorizationCustomEndpoint = false diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index b94b82127..0cc3630e1 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -15,6 +15,7 @@ const ( OutputFormatKey = "output_format" ProjectIdKey = "project_id" SessionTimeLimitKey = "session_time_limit" + VerbosityKey = "verbosity" ArgusCustomEndpointKey = "argus_custom_endpoint" AuthorizationCustomEndpointKey = "authorization_custom_endpoint" @@ -49,6 +50,7 @@ var ConfigKeys = []string{ OutputFormatKey, ProjectIdKey, SessionTimeLimitKey, + VerbosityKey, DNSCustomEndpointKey, LogMeCustomEndpointKey, diff --git a/internal/pkg/globalflags/global_flags.go b/internal/pkg/globalflags/global_flags.go index 144033314..f0a3e3e1a 100644 --- a/internal/pkg/globalflags/global_flags.go +++ b/internal/pkg/globalflags/global_flags.go @@ -16,12 +16,21 @@ const ( AssumeYesFlag = "assume-yes" OutputFormatFlag = "output-format" ProjectIdFlag = "project-id" + VerbosityFlag = "verbosity" JSONOutputFormat = "json" PrettyOutputFormat = "pretty" + + DebugVerbosity = "debug" + InfoVerbosity = "info" + WarningVerbosity = "warning" + ErrorVerbosity = "error" + + VerbosityDefault = InfoVerbosity ) var outputFormatFlagOptions = []string{JSONOutputFormat, PrettyOutputFormat} +var verbosityFlagOptions = []string{DebugVerbosity, InfoVerbosity, WarningVerbosity, ErrorVerbosity} type GlobalFlagModel struct { Async bool @@ -50,6 +59,13 @@ func Configure(flagSet *pflag.FlagSet) error { } flagSet.BoolP(AssumeYesFlag, "y", false, "If set, skips all confirmation prompts") + + flagSet.Var(flags.EnumFlag(true, VerbosityDefault, verbosityFlagOptions...), VerbosityFlag, fmt.Sprintf("Verbosity of the CLI, one of %q", verbosityFlagOptions)) + err = viper.BindPFlag(config.VerbosityKey, flagSet.Lookup(VerbosityFlag)) + if err != nil { + return fmt.Errorf("bind --%s flag to config: %w", VerbosityFlag, err) + } + return nil }