Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions docs/stackit_config_unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ stackit config unset [flags]

```
--allowed-url-domain Domain name, used for the verification of the URLs that are given in the IDP endpoint and curl commands. If unset, defaults to stackit.cloud
--assume-yes If set, skips all confirmation prompts
--async Configuration option to run commands asynchronously
--authorization-custom-endpoint Authorization API base URL. If unset, uses the default base URL
--cdn-custom-endpoint Custom CDN endpoint URL. If unset, uses the default base URL
Expand Down Expand Up @@ -67,12 +68,6 @@ stackit config unset [flags]
--verbosity Verbosity of the CLI
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
```

### SEE ALSO

* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/config/unset/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
projectIdFlag = globalflags.ProjectIdFlag
regionFlag = globalflags.RegionFlag
verbosityFlag = globalflags.VerbosityFlag
assumeYesFlag = globalflags.AssumeYesFlag

sessionTimeLimitFlag = "session-time-limit"
identityProviderCustomWellKnownConfigurationFlag = "identity-provider-custom-well-known-configuration"
Expand Down Expand Up @@ -65,6 +66,7 @@ type inputModel struct {
ProjectId bool
Region bool
Verbosity bool
AssumeYes bool

SessionTimeLimit bool
IdentityProviderCustomEndpoint bool
Expand Down Expand Up @@ -137,6 +139,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if model.Verbosity {
viper.Set(config.VerbosityKey, globalflags.VerbosityDefault)
}
if model.AssumeYes {
viper.Set(config.AssumeYesKey, config.AssumeYesDefault)
}

if model.SessionTimeLimit {
viper.Set(config.SessionTimeLimitKey, config.SessionTimeLimitDefault)
Expand Down Expand Up @@ -256,6 +261,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(regionFlag, false, "Region")
cmd.Flags().Bool(outputFormatFlag, false, "Output format")
cmd.Flags().Bool(verbosityFlag, false, "Verbosity of the CLI")
cmd.Flags().Bool(assumeYesFlag, false, "If set, skips all confirmation prompts")

cmd.Flags().Bool(sessionTimeLimitFlag, false, fmt.Sprintf("Maximum time before authentication is required again. If unset, defaults to %s", config.SessionTimeLimitDefault))
cmd.Flags().Bool(identityProviderCustomWellKnownConfigurationFlag, false, "Identity Provider well-known OpenID configuration URL. If unset, uses the default identity provider")
Expand Down Expand Up @@ -300,6 +306,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
ProjectId: flags.FlagToBoolValue(p, cmd, projectIdFlag),
Region: flags.FlagToBoolValue(p, cmd, regionFlag),
Verbosity: flags.FlagToBoolValue(p, cmd, verbosityFlag),
AssumeYes: flags.FlagToBoolValue(p, cmd, assumeYesFlag),

SessionTimeLimit: flags.FlagToBoolValue(p, cmd, sessionTimeLimitFlag),
IdentityProviderCustomEndpoint: flags.FlagToBoolValue(p, cmd, identityProviderCustomWellKnownConfigurationFlag),
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/config/unset/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool
outputFormatFlag: true,
projectIdFlag: true,
verbosityFlag: true,
assumeYesFlag: true,

sessionTimeLimitFlag: true,
identityProviderCustomWellKnownConfigurationFlag: true,
Expand Down Expand Up @@ -62,6 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
OutputFormat: true,
ProjectId: true,
Verbosity: true,
AssumeYes: true,

SessionTimeLimit: true,
IdentityProviderCustomEndpoint: true,
Expand Down Expand Up @@ -123,6 +125,7 @@ func TestParseInput(t *testing.T) {
model.OutputFormat = false
model.ProjectId = false
model.Verbosity = false
model.AssumeYes = false

model.SessionTimeLimit = false
model.IdentityProviderCustomEndpoint = false
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
RegionKey = "region"
SessionTimeLimitKey = "session_time_limit"
VerbosityKey = "verbosity"
AssumeYesKey = "assume_yes"

IdentityProviderCustomWellKnownConfigurationKey = "identity_provider_custom_well_known_configuration"
IdentityProviderCustomClientIdKey = "identity_provider_custom_client_id"
Expand Down Expand Up @@ -58,6 +59,7 @@ const (
DefaultProfileName = "default"

AsyncDefault = false
AssumeYesDefault = false
RegionDefault = "eu01"
SessionTimeLimitDefault = "12h"

Expand All @@ -82,6 +84,7 @@ var ConfigKeys = []string{
RegionKey,
SessionTimeLimitKey,
VerbosityKey,
AssumeYesKey,

IdentityProviderCustomWellKnownConfigurationKey,
IdentityProviderCustomClientIdKey,
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/globalflags/global_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func Configure(flagSet *pflag.FlagSet) error {
}

flagSet.BoolP(AssumeYesFlag, "y", false, "If set, skips all confirmation prompts")
err = viper.BindPFlag(config.AssumeYesKey, flagSet.Lookup(AssumeYesFlag))
if err != nil {
return fmt.Errorf("bind --%s flag to config: %w", AssumeYesFlag, err)
}

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))
Expand All @@ -76,10 +80,10 @@ func Configure(flagSet *pflag.FlagSet) error {
return nil
}

func Parse(p *print.Printer, cmd *cobra.Command) *GlobalFlagModel {
func Parse(_ *print.Printer, _ *cobra.Command) *GlobalFlagModel {
return &GlobalFlagModel{
Async: viper.GetBool(config.AsyncKey),
AssumeYes: flags.FlagToBoolValue(p, cmd, AssumeYesFlag),
AssumeYes: viper.GetBool(config.AssumeYesKey),
OutputFormat: viper.GetString(config.OutputFormatKey),
ProjectId: viper.GetString(config.ProjectIdKey),
Region: viper.GetString(config.RegionKey),
Expand Down
Loading