diff --git a/cmd/scw/testdata/test-all-usage-alias-usage.golden b/cmd/scw/testdata/test-all-usage-alias-usage.golden index 35a2228cf9..f22c7f48d5 100644 --- a/cmd/scw/testdata/test-all-usage-alias-usage.golden +++ b/cmd/scw/testdata/test-all-usage-alias-usage.golden @@ -1,12 +1,12 @@ 🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ This namespace allows you to manage your aliases -Aliases are store in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order: - $SCW_CLI_CONFIG_PATH -- $XDG_CONFIG_HOME/scw/cli.yaml -- $HOME/.config/scw/cli.yaml -- $USERPROFILE/.config/scw/cli.yaml +- $XDG_CONFIG_HOME/scw/config.yaml +- $HOME/.config/scw/config.yaml +- $USERPROFILE/.config/scw/config.yaml You can use multiple aliases in one command aliases in your commands are evaluated and you get completion diff --git a/core/bootstrap.go b/core/bootstrap.go index 6e911dc31d..4d78e62341 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -209,7 +209,7 @@ func Bootstrap(config *BootstrapConfig) (exitCode int, result interface{}, err e ctx = InjectMeta(ctx, meta) // Load CLI config - cliCfg, err := cliConfig.LoadConfig(ExtractCliConfigPath(ctx)) + cliCfg, err := cliConfig.LoadConfig(ExtractConfigPath(ctx)) if err != nil { printErr := printer.Print(err, nil) if printErr != nil { diff --git a/core/context.go b/core/context.go index a79255e68c..f37d2f8a35 100644 --- a/core/context.go +++ b/core/context.go @@ -176,19 +176,9 @@ func ExtractHTTPClient(ctx context.Context) *http.Client { func ExtractConfigPath(ctx context.Context) string { meta := extractMeta(ctx) if meta.ConfigPathFlag != "" { - return extractMeta(ctx).ConfigPathFlag + return meta.ConfigPathFlag } // This is only useful for test when we override home environment variable - if home := meta.OverrideEnv["HOME"]; home != "" { - return path.Join(home, ".config", "scw", "config.yaml") - } - - return scw.GetConfigPath() -} - -func ExtractCliConfigPath(ctx context.Context) string { - meta := extractMeta(ctx) - // This is only useful for test when we override home environment variable if home := meta.OverrideEnv["HOME"]; home != "" { return path.Join(home, ".config", "scw", cliConfig.DefaultConfigFileName) } diff --git a/docs/commands/alias.md b/docs/commands/alias.md index 744359aac2..a8d5283a15 100644 --- a/docs/commands/alias.md +++ b/docs/commands/alias.md @@ -1,12 +1,12 @@ # Documentation for `scw alias` This namespace allows you to manage your aliases -Aliases are store in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order: - $SCW_CLI_CONFIG_PATH -- $XDG_CONFIG_HOME/scw/cli.yaml -- $HOME/.config/scw/cli.yaml -- $USERPROFILE/.config/scw/cli.yaml +- $XDG_CONFIG_HOME/scw/config.yaml +- $HOME/.config/scw/config.yaml +- $USERPROFILE/.config/scw/config.yaml You can use multiple aliases in one command aliases in your commands are evaluated and you get completion diff --git a/internal/config/config.go b/internal/config/config.go index caedeb848f..89f3ae253e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -16,7 +16,7 @@ import ( const ( ScwConfigPathEnv = "SCW_CLI_CONFIG_PATH" - DefaultConfigFileName = "cli.yaml" + DefaultConfigFileName = "config.yaml" defaultConfigPermission = 0o644 DefaultOutput = "human" diff --git a/internal/namespaces/alias/alias.go b/internal/namespaces/alias/alias.go index 1b9463fa99..9ae2f90188 100644 --- a/internal/namespaces/alias/alias.go +++ b/internal/namespaces/alias/alias.go @@ -25,12 +25,12 @@ func aliasRootCommand() *core.Command { Groups: []string{"config"}, Short: "Alias related commands", Long: `This namespace allows you to manage your aliases -Aliases are store in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order: - $SCW_CLI_CONFIG_PATH -- $XDG_CONFIG_HOME/scw/cli.yaml -- $HOME/.config/scw/cli.yaml -- $USERPROFILE/.config/scw/cli.yaml +- $XDG_CONFIG_HOME/scw/config.yaml +- $HOME/.config/scw/config.yaml +- $USERPROFILE/.config/scw/config.yaml You can use multiple aliases in one command aliases in your commands are evaluated and you get completion diff --git a/internal/namespaces/config/commands.go b/internal/namespaces/config/commands.go index 967effef9f..3e0996c0fa 100644 --- a/internal/namespaces/config/commands.go +++ b/internal/namespaces/config/commands.go @@ -290,7 +290,12 @@ The only allowed attributes are access_key, secret_key, default_organization_id, configPath := core.ExtractConfigPath(ctx) config, err := scw.LoadConfigFromPath(configPath) if err != nil { - return nil, err + if strings.Contains(err.Error(), "no such file or directory") { + fmt.Fprintln(os.Stdout, "config file not found, will attempt to create it") + config = &scw.Config{} + } else { + return nil, err + } } // send_telemetry is the only key that is not in a profile but in the config object directly @@ -316,7 +321,6 @@ The only allowed attributes are access_key, secret_key, default_organization_id, profileValue.Field(i).Set(field) } } - // Save err = config.SaveTo(configPath) if err != nil {