Skip to content

Commit 49e9b9b

Browse files
authored
Revert "fix(config): use SCW_CLI_CONFIG_PATH with set config" (#4858)
1 parent 6eb14c1 commit 49e9b9b

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

cmd/scw/testdata/test-all-usage-alias-usage.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
33
This namespace allows you to manage your aliases
4-
Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order:
4+
Aliases are store in cli config file, Default path for this configuration file is based on the following priority order:
55

66
- $SCW_CLI_CONFIG_PATH
7-
- $XDG_CONFIG_HOME/scw/config.yaml
8-
- $HOME/.config/scw/config.yaml
9-
- $USERPROFILE/.config/scw/config.yaml
7+
- $XDG_CONFIG_HOME/scw/cli.yaml
8+
- $HOME/.config/scw/cli.yaml
9+
- $USERPROFILE/.config/scw/cli.yaml
1010

1111
You can use multiple aliases in one command
1212
aliases in your commands are evaluated and you get completion

core/bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func Bootstrap(config *BootstrapConfig) (exitCode int, result any, err error) {
209209
ctx = InjectMeta(ctx, meta)
210210

211211
// Load CLI config
212-
cliCfg, err := cliConfig.LoadConfig(ExtractConfigPath(ctx))
212+
cliCfg, err := cliConfig.LoadConfig(ExtractCliConfigPath(ctx))
213213
if err != nil {
214214
printErr := printer.Print(err, nil)
215215
if printErr != nil {

core/context.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,19 @@ func ExtractHTTPClient(ctx context.Context) *http.Client {
176176
func ExtractConfigPath(ctx context.Context) string {
177177
meta := extractMeta(ctx)
178178
if meta.ConfigPathFlag != "" {
179-
return meta.ConfigPathFlag
179+
return extractMeta(ctx).ConfigPathFlag
180180
}
181181
// This is only useful for test when we override home environment variable
182+
if home := meta.OverrideEnv["HOME"]; home != "" {
183+
return path.Join(home, ".config", "scw", "config.yaml")
184+
}
185+
186+
return scw.GetConfigPath()
187+
}
188+
189+
func ExtractCliConfigPath(ctx context.Context) string {
190+
meta := extractMeta(ctx)
191+
// This is only useful for test when we override home environment variable
182192
if home := meta.OverrideEnv["HOME"]; home != "" {
183193
return path.Join(home, ".config", "scw", cliConfig.DefaultConfigFileName)
184194
}

docs/commands/alias.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
22
# Documentation for `scw alias`
33
This namespace allows you to manage your aliases
4-
Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order:
4+
Aliases are store in cli config file, Default path for this configuration file is based on the following priority order:
55

66
- $SCW_CLI_CONFIG_PATH
7-
- $XDG_CONFIG_HOME/scw/config.yaml
8-
- $HOME/.config/scw/config.yaml
9-
- $USERPROFILE/.config/scw/config.yaml
7+
- $XDG_CONFIG_HOME/scw/cli.yaml
8+
- $HOME/.config/scw/cli.yaml
9+
- $USERPROFILE/.config/scw/cli.yaml
1010

1111
You can use multiple aliases in one command
1212
aliases in your commands are evaluated and you get completion

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const (
1717
ScwConfigPathEnv = "SCW_CLI_CONFIG_PATH"
1818

19-
DefaultConfigFileName = "config.yaml"
19+
DefaultConfigFileName = "cli.yaml"
2020
defaultConfigPermission = 0o644
2121

2222
DefaultOutput = "human"

internal/namespaces/alias/alias.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ func aliasRootCommand() *core.Command {
2525
Groups: []string{"config"},
2626
Short: "Alias related commands",
2727
Long: `This namespace allows you to manage your aliases
28-
Aliases are stored in cli config file, Default path for this configuration file is based on the following priority order:
28+
Aliases are store in cli config file, Default path for this configuration file is based on the following priority order:
2929
3030
- $SCW_CLI_CONFIG_PATH
31-
- $XDG_CONFIG_HOME/scw/config.yaml
32-
- $HOME/.config/scw/config.yaml
33-
- $USERPROFILE/.config/scw/config.yaml
31+
- $XDG_CONFIG_HOME/scw/cli.yaml
32+
- $HOME/.config/scw/cli.yaml
33+
- $USERPROFILE/.config/scw/cli.yaml
3434
3535
You can use multiple aliases in one command
3636
aliases in your commands are evaluated and you get completion

internal/namespaces/config/commands.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,7 @@ The only allowed attributes are access_key, secret_key, default_organization_id,
290290
configPath := core.ExtractConfigPath(ctx)
291291
config, err := scw.LoadConfigFromPath(configPath)
292292
if err != nil {
293-
if strings.Contains(err.Error(), "no such file or directory") {
294-
fmt.Fprintln(os.Stdout, "config file not found, will attempt to create it")
295-
config = &scw.Config{}
296-
} else {
297-
return nil, err
298-
}
293+
return nil, err
299294
}
300295

301296
// 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,
321316
profileValue.Field(i).Set(field)
322317
}
323318
}
319+
324320
// Save
325321
err = config.SaveTo(configPath)
326322
if err != nil {

0 commit comments

Comments
 (0)