Skip to content

Commit d200474

Browse files
authored
fix(config): use SCW_CLI_CONFIG_PATH with set config (#4682)
1 parent 76a5b31 commit d200474

File tree

7 files changed

+21
-27
lines changed

7 files changed

+21
-27
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 store in cli config file, Default path for this configuration file is based on the following priority order:
4+
Aliases are stored 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/cli.yaml
8-
- $HOME/.config/scw/cli.yaml
9-
- $USERPROFILE/.config/scw/cli.yaml
7+
- $XDG_CONFIG_HOME/scw/config.yaml
8+
- $HOME/.config/scw/config.yaml
9+
- $USERPROFILE/.config/scw/config.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 interface{}, err e
209209
ctx = InjectMeta(ctx, meta)
210210

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

core/context.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,9 @@ func ExtractHTTPClient(ctx context.Context) *http.Client {
176176
func ExtractConfigPath(ctx context.Context) string {
177177
meta := extractMeta(ctx)
178178
if meta.ConfigPathFlag != "" {
179-
return extractMeta(ctx).ConfigPathFlag
179+
return meta.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
192182
if home := meta.OverrideEnv["HOME"]; home != "" {
193183
return path.Join(home, ".config", "scw", cliConfig.DefaultConfigFileName)
194184
}

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 store in cli config file, Default path for this configuration file is based on the following priority order:
4+
Aliases are stored 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/cli.yaml
8-
- $HOME/.config/scw/cli.yaml
9-
- $USERPROFILE/.config/scw/cli.yaml
7+
- $XDG_CONFIG_HOME/scw/config.yaml
8+
- $HOME/.config/scw/config.yaml
9+
- $USERPROFILE/.config/scw/config.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 = "cli.yaml"
19+
DefaultConfigFileName = "config.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 store in cli config file, Default path for this configuration file is based on the following priority order:
28+
Aliases are stored 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/cli.yaml
32-
- $HOME/.config/scw/cli.yaml
33-
- $USERPROFILE/.config/scw/cli.yaml
31+
- $XDG_CONFIG_HOME/scw/config.yaml
32+
- $HOME/.config/scw/config.yaml
33+
- $USERPROFILE/.config/scw/config.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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,12 @@ 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-
return nil, err
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+
}
294299
}
295300

296301
// 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,
316321
profileValue.Field(i).Set(field)
317322
}
318323
}
319-
320324
// Save
321325
err = config.SaveTo(configPath)
322326
if err != nil {

0 commit comments

Comments
 (0)