Skip to content

Commit f0b62cb

Browse files
committed
Fix default config file not found
1 parent 27ec121 commit f0b62cb

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Diff for: configuration/configuration.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ func Init(configPath string) {
4343
viper.SetConfigName("arduino-cli")
4444
}
4545

46-
// Get default data path if none was provided
47-
if configPath == "" {
48-
configPath = getDefaultArduinoDataDir()
49-
}
50-
51-
// Add paths where to search for a config file
52-
viper.AddConfigPath(filepath.Dir(configPath))
53-
5446
// Bind env vars
5547
viper.SetEnvPrefix("ARDUINO")
5648
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
@@ -61,6 +53,18 @@ func Init(configPath string) {
6153
viper.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR")
6254
viper.BindEnv("directories.Data", "ARDUINO_DATA_DIR")
6355

56+
if configPath == "" {
57+
// Get default data path if none was provided
58+
if configPath = viper.GetString("directories.Data"); configPath != "" {
59+
viper.AddConfigPath(configPath)
60+
} else {
61+
configPath = getDefaultArduinoDataDir()
62+
viper.AddConfigPath(configPath)
63+
}
64+
} else {
65+
viper.AddConfigPath(filepath.Dir(configPath))
66+
}
67+
6468
// Early access directories.Data and directories.User in case
6569
// those were set through env vars or cli flags
6670
dataDir := viper.GetString("directories.Data")

Diff for: test/test_config.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,30 @@ def test_init_config_file_flag_with_overwrite_flag(run_command, working_dir):
102102
assert str(config_file) in result.stdout
103103

104104

105-
def test_dump(run_command, working_dir):
105+
def test_dump(run_command, data_dir, working_dir):
106106
# Create a config file first
107107
config_file = Path(working_dir) / "config" / "test" / "config.yaml"
108108
assert not config_file.exists()
109109
result = run_command(f'config init --dest-file "{config_file}"')
110110
assert result.ok
111111
assert config_file.exists()
112112

113-
result = run_command("config dump --format json")
113+
result = run_command(f'config dump --config-file "{config_file}" --format json')
114114
assert result.ok
115115
settings_json = json.loads(result.stdout)
116116
assert [] == settings_json["board_manager"]["additional_urls"]
117117

118+
result = run_command('config init --additional-urls "https://example.com"')
119+
assert result.ok
120+
config_file = Path(data_dir) / "arduino-cli.yaml"
121+
assert str(config_file) in result.stdout
122+
assert config_file.exists()
123+
124+
result = run_command("config dump --format json")
125+
assert result.ok
126+
settings_json = json.loads(result.stdout)
127+
assert ["https://example.com"] == settings_json["board_manager"]["additional_urls"]
128+
118129

119130
def test_dump_with_config_file_flag(run_command, working_dir):
120131
# Create a config file first

0 commit comments

Comments
 (0)