Skip to content

Commit eae6983

Browse files
committed
feat(config) allow setting assume-yes in config
fixes #1212 related: STACKITCLI-327 kubectl calls stackit-cli for auth. To enable e2e tests for this ske feature, it would be nice to save assume-yes to the config.
1 parent b7bad48 commit eae6983

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

docs/stackit_config_unset.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ stackit config unset [flags]
2727

2828
```
2929
--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
30+
--assume-yes If set, skips all confirmation prompts
3031
--async Configuration option to run commands asynchronously
3132
--authorization-custom-endpoint Authorization API base URL. If unset, uses the default base URL
3233
--cdn-custom-endpoint Custom CDN endpoint URL. If unset, uses the default base URL
@@ -67,12 +68,6 @@ stackit config unset [flags]
6768
--verbosity Verbosity of the CLI
6869
```
6970

70-
### Options inherited from parent commands
71-
72-
```
73-
-y, --assume-yes If set, skips all confirmation prompts
74-
```
75-
7671
### SEE ALSO
7772

7873
* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options

internal/cmd/config/unset/unset.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
projectIdFlag = globalflags.ProjectIdFlag
2323
regionFlag = globalflags.RegionFlag
2424
verbosityFlag = globalflags.VerbosityFlag
25+
assumeYesFlag = globalflags.AssumeYesFlag
2526

2627
sessionTimeLimitFlag = "session-time-limit"
2728
identityProviderCustomWellKnownConfigurationFlag = "identity-provider-custom-well-known-configuration"
@@ -65,6 +66,7 @@ type inputModel struct {
6566
ProjectId bool
6667
Region bool
6768
Verbosity bool
69+
AssumeYes bool
6870

6971
SessionTimeLimit bool
7072
IdentityProviderCustomEndpoint bool
@@ -137,6 +139,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
137139
if model.Verbosity {
138140
viper.Set(config.VerbosityKey, globalflags.VerbosityDefault)
139141
}
142+
if model.AssumeYes {
143+
viper.Set(config.AssumeYesKey, config.AssumeYesDefault)
144+
}
140145

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

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

304311
SessionTimeLimit: flags.FlagToBoolValue(p, cmd, sessionTimeLimitFlag),
305312
IdentityProviderCustomEndpoint: flags.FlagToBoolValue(p, cmd, identityProviderCustomWellKnownConfigurationFlag),

internal/pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
RegionKey = "region"
1818
SessionTimeLimitKey = "session_time_limit"
1919
VerbosityKey = "verbosity"
20+
AssumeYesKey = "assume_yes"
2021

2122
IdentityProviderCustomWellKnownConfigurationKey = "identity_provider_custom_well_known_configuration"
2223
IdentityProviderCustomClientIdKey = "identity_provider_custom_client_id"
@@ -58,6 +59,7 @@ const (
5859
DefaultProfileName = "default"
5960

6061
AsyncDefault = false
62+
AssumeYesDefault = false
6163
RegionDefault = "eu01"
6264
SessionTimeLimitDefault = "12h"
6365

@@ -82,6 +84,7 @@ var ConfigKeys = []string{
8284
RegionKey,
8385
SessionTimeLimitKey,
8486
VerbosityKey,
87+
AssumeYesKey,
8588

8689
IdentityProviderCustomWellKnownConfigurationKey,
8790
IdentityProviderCustomClientIdKey,

internal/pkg/globalflags/global_flags.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func Configure(flagSet *pflag.FlagSet) error {
6060
}
6161

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

6468
flagSet.Var(flags.EnumFlag(true, VerbosityDefault, verbosityFlagOptions...), VerbosityFlag, fmt.Sprintf("Verbosity of the CLI, one of %q", verbosityFlagOptions))
6569
err = viper.BindPFlag(config.VerbosityKey, flagSet.Lookup(VerbosityFlag))
@@ -79,7 +83,7 @@ func Configure(flagSet *pflag.FlagSet) error {
7983
func Parse(p *print.Printer, cmd *cobra.Command) *GlobalFlagModel {
8084
return &GlobalFlagModel{
8185
Async: viper.GetBool(config.AsyncKey),
82-
AssumeYes: flags.FlagToBoolValue(p, cmd, AssumeYesFlag),
86+
AssumeYes: viper.GetBool(config.AssumeYesKey),
8387
OutputFormat: viper.GetString(config.OutputFormatKey),
8488
ProjectId: viper.GetString(config.ProjectIdKey),
8589
Region: viper.GetString(config.RegionKey),

0 commit comments

Comments
 (0)