diff --git a/cmd/scw/testdata/test-all-usage-alias-usage.golden b/cmd/scw/testdata/test-all-usage-alias-usage.golden index f22c7f48d5..35a2228cf9 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 stored in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are store 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/config.yaml -- $HOME/.config/scw/config.yaml -- $USERPROFILE/.config/scw/config.yaml +- $XDG_CONFIG_HOME/scw/cli.yaml +- $HOME/.config/scw/cli.yaml +- $USERPROFILE/.config/scw/cli.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 658d0ac562..f8dcf9ff2e 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -209,7 +209,7 @@ func Bootstrap(config *BootstrapConfig) (exitCode int, result any, err error) { ctx = InjectMeta(ctx, meta) // Load CLI config - cliCfg, err := cliConfig.LoadConfig(ExtractConfigPath(ctx)) + cliCfg, err := cliConfig.LoadConfig(ExtractCliConfigPath(ctx)) if err != nil { printErr := printer.Print(err, nil) if printErr != nil { diff --git a/core/context.go b/core/context.go index 6c4fbcb3c5..6d3b89e3cf 100644 --- a/core/context.go +++ b/core/context.go @@ -176,9 +176,19 @@ func ExtractHTTPClient(ctx context.Context) *http.Client { func ExtractConfigPath(ctx context.Context) string { meta := extractMeta(ctx) if meta.ConfigPathFlag != "" { - return meta.ConfigPathFlag + return extractMeta(ctx).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 a8d5283a15..744359aac2 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 stored in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are store 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/config.yaml -- $HOME/.config/scw/config.yaml -- $USERPROFILE/.config/scw/config.yaml +- $XDG_CONFIG_HOME/scw/cli.yaml +- $HOME/.config/scw/cli.yaml +- $USERPROFILE/.config/scw/cli.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 89f3ae253e..caedeb848f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -16,7 +16,7 @@ import ( const ( ScwConfigPathEnv = "SCW_CLI_CONFIG_PATH" - DefaultConfigFileName = "config.yaml" + DefaultConfigFileName = "cli.yaml" defaultConfigPermission = 0o644 DefaultOutput = "human" diff --git a/internal/namespaces/alias/alias.go b/internal/namespaces/alias/alias.go index de3375f02f..4b27618272 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 stored in cli config file, Default path for this configuration file is based on the following priority order: +Aliases are store 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/config.yaml -- $HOME/.config/scw/config.yaml -- $USERPROFILE/.config/scw/config.yaml +- $XDG_CONFIG_HOME/scw/cli.yaml +- $HOME/.config/scw/cli.yaml +- $USERPROFILE/.config/scw/cli.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 748ece2387..748589e4c7 100644 --- a/internal/namespaces/config/commands.go +++ b/internal/namespaces/config/commands.go @@ -290,12 +290,7 @@ The only allowed attributes are access_key, secret_key, default_organization_id, configPath := core.ExtractConfigPath(ctx) config, err := scw.LoadConfigFromPath(configPath) if err != nil { - 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 - } + return nil, err } // send_telemetry is the only key that is not in a profile but in the config object directly @@ -321,6 +316,7 @@ 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 {