diff --git a/configuration/configuration.go b/configuration/configuration.go index 0afcd015bf3..3593f4111b7 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -136,9 +136,9 @@ func GetDefaultBuiltinLibrariesDir() string { return filepath.Join(getDefaultArduinoDataDir(), "libraries") } -// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the +// FindConfigFileInArgs returns the config file path using the // argument '--config-file' (if specified) or looking in the current working dir -func FindConfigFileInArgsOrWorkingDirectory(args []string) string { +func FindConfigFileInArgs(args []string) string { // Look for '--config-file' argument for i, arg := range args { if arg == "--config-file" { @@ -147,23 +147,5 @@ func FindConfigFileInArgsOrWorkingDirectory(args []string) string { } } } - - // Look into current working directory - if cwd, err := paths.Getwd(); err != nil { - return "" - } else if configFile := searchConfigTree(cwd); configFile != nil { - return configFile.Join("arduino-cli.yaml").String() - } return "" } - -func searchConfigTree(cwd *paths.Path) *paths.Path { - // go back up to root and search for the config file - for _, path := range cwd.Parents() { - if path.Join("arduino-cli.yaml").Exist() { - return path - } - } - - return nil -} diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 880b40a32f2..ce879e0c8d3 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -21,7 +21,6 @@ import ( "path/filepath" "testing" - paths "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" ) @@ -39,45 +38,6 @@ func tmpDirOrDie() string { return dir } -func TestSearchConfigTreeNotFound(t *testing.T) { - tmp := tmpDirOrDie() - require.Empty(t, searchConfigTree(paths.New(tmp))) -} - -func TestSearchConfigTreeSameFolder(t *testing.T) { - tmp := tmpDirOrDie() - defer os.RemoveAll(tmp) - _, err := os.Create(filepath.Join(tmp, "arduino-cli.yaml")) - require.Nil(t, err) - require.Equal(t, tmp, searchConfigTree(paths.New(tmp)).String()) -} - -func TestSearchConfigTreeInParent(t *testing.T) { - tmp := tmpDirOrDie() - defer os.RemoveAll(tmp) - target := filepath.Join(tmp, "foo", "bar") - err := os.MkdirAll(target, os.ModePerm) - require.Nil(t, err) - _, err = os.Create(filepath.Join(tmp, "arduino-cli.yaml")) - require.Nil(t, err) - require.Equal(t, tmp, searchConfigTree(paths.New(target)).String()) -} - -var result *paths.Path - -func BenchmarkSearchConfigTree(b *testing.B) { - tmp := tmpDirOrDie() - defer os.RemoveAll(tmp) - target := filepath.Join(tmp, "foo", "bar", "baz") - os.MkdirAll(target, os.ModePerm) - - var s *paths.Path - for n := 0; n < b.N; n++ { - s = searchConfigTree(paths.New(target)) - } - result = s -} - func TestInit(t *testing.T) { tmp := tmpDirOrDie() defer os.RemoveAll(tmp) @@ -100,38 +60,15 @@ func TestInit(t *testing.T) { } func TestFindConfigFile(t *testing.T) { - configFile := FindConfigFileInArgsOrWorkingDirectory([]string{"--config-file"}) + configFile := FindConfigFileInArgs([]string{"--config-file"}) require.Equal(t, "", configFile) - configFile = FindConfigFileInArgsOrWorkingDirectory([]string{"--config-file", "some/path/to/config"}) + configFile = FindConfigFileInArgs([]string{"--config-file", "some/path/to/config"}) require.Equal(t, "some/path/to/config", configFile) - configFile = FindConfigFileInArgsOrWorkingDirectory([]string{"--config-file", "some/path/to/config/arduino-cli.yaml"}) + configFile = FindConfigFileInArgs([]string{"--config-file", "some/path/to/config/arduino-cli.yaml"}) require.Equal(t, "some/path/to/config/arduino-cli.yaml", configFile) - configFile = FindConfigFileInArgsOrWorkingDirectory([]string{}) + configFile = FindConfigFileInArgs([]string{}) require.Equal(t, "", configFile) - - // Create temporary directories - tmp := tmpDirOrDie() - defer os.RemoveAll(tmp) - target := filepath.Join(tmp, "foo", "bar", "baz") - os.MkdirAll(target, os.ModePerm) - require.Nil(t, os.Chdir(target)) - - // Create a config file - f, err := os.Create(filepath.Join(target, "..", "..", "arduino-cli.yaml")) - require.Nil(t, err) - f.Close() - - configFile = FindConfigFileInArgsOrWorkingDirectory([]string{}) - require.Equal(t, filepath.Join(tmp, "foo", "arduino-cli.yaml"), configFile) - - // Create another config file - f, err = os.Create(filepath.Join(target, "arduino-cli.yaml")) - require.Nil(t, err) - f.Close() - - configFile = FindConfigFileInArgsOrWorkingDirectory([]string{}) - require.Equal(t, filepath.Join(target, "arduino-cli.yaml"), configFile) } diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index 0860f5a4a01..819882bbb68 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -2,6 +2,11 @@ Here you can find a list of migration guides to handle breaking changes between releases of the CLI. +## 0.32.0 + +Configuration file lookup in current working directory and its parents is dropped. The command line flag `--config-file` +must be specified to use an alternative configuration file from the one in the data directory. + ## 0.31.0 ### Added `post_install` script support for tools diff --git a/docs/configuration.md b/docs/configuration.md index b03cbaa3e25..83a8662acd7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -116,8 +116,6 @@ The configuration file must be named `arduino-cli`, with the appropriate file ex Configuration files in the following locations are recognized by Arduino CLI: 1. Location specified by the [`--config-file`][arduino cli command reference] command line flag -1. Current working directory -1. Any parent directory of the current working directory (more immediate parents having higher precedence) 1. Arduino CLI data directory (as configured by `directories.data`) If multiple configuration files are present, the one highest on the above list is used. Configuration files are not diff --git a/docsgen/main.go b/docsgen/main.go index aaac2d3bd0e..5bb4a3fcc4b 100644 --- a/docsgen/main.go +++ b/docsgen/main.go @@ -31,7 +31,7 @@ func main() { os.MkdirAll(os.Args[1], 0755) // Create the output folder if it doesn't already exist - configuration.Settings = configuration.Init(configuration.FindConfigFileInArgsOrWorkingDirectory(os.Args)) + configuration.Settings = configuration.Init(configuration.FindConfigFileInArgs(os.Args)) cli := cli.NewCommand() cli.DisableAutoGenTag = true // Disable addition of auto-generated date stamp err := doc.GenMarkdownTree(cli, os.Args[1]) diff --git a/internal/integrationtest/compile_1/compile_test.go b/internal/integrationtest/compile_1/compile_test.go index 998fe7c0483..174d8f1eaf9 100644 --- a/internal/integrationtest/compile_1/compile_test.go +++ b/internal/integrationtest/compile_1/compile_test.go @@ -526,7 +526,7 @@ func compileWithExportBinariesConfig(t *testing.T, env *integrationtest.Environm defer cli.WorkingDir().Join("arduino-cli.yaml").Remove() // Test if arduino-cli config file written in the previous run has the `always_export_binaries` flag set. - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Contains(t, stdout, ` { @@ -536,7 +536,7 @@ func compileWithExportBinariesConfig(t *testing.T, env *integrationtest.Environm }`) // Test compilation with export binaries env var set - _, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String()) + _, _, err = cli.Run("compile", "-b", fqbn, "--config-file", "arduino-cli.yaml", sketchPath.String()) require.NoError(t, err) require.DirExists(t, sketchPath.Join("build").String()) @@ -563,7 +563,7 @@ func compileWithInvalidUrl(t *testing.T, env *integrationtest.Environment, cli * require.NoError(t, err) defer cli.WorkingDir().Join("arduino-cli.yaml").Remove() - _, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String()) + _, stderr, err := cli.Run("compile", "-b", fqbn, "--config-file", "arduino-cli.yaml", sketchPath.String()) require.NoError(t, err) require.Contains(t, string(stderr), "Error initializing instance: Loading index file: loading json index file") expectedIndexfile := cli.DataDir().Join("package_example_index.json") @@ -813,10 +813,10 @@ func TestCompileWithCustomLibraries(t *testing.T) { require.NoError(t, err) // Init the environment explicitly - _, _, err = cli.Run("update") + _, _, err = cli.Run("update", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - _, _, err = cli.Run("core", "install", "esp8266:esp8266") + _, _, err = cli.Run("core", "install", "esp8266:esp8266", "--config-file", "arduino-cli.yaml") require.NoError(t, err) sketchName := "sketch_with_multiple_custom_libraries" @@ -825,7 +825,12 @@ func TestCompileWithCustomLibraries(t *testing.T) { firstLib := sketchPath.Join("libraries1") secondLib := sketchPath.Join("libraries2") - _, _, err = cli.Run("compile", "--libraries", firstLib.String(), "--libraries", secondLib.String(), "-b", fqbn, sketchPath.String()) + _, _, err = cli.Run("compile", "--libraries", + firstLib.String(), + "--libraries", secondLib.String(), + "-b", fqbn, + "--config-file", "arduino-cli.yaml", + sketchPath.String()) require.NoError(t, err) } @@ -839,18 +844,18 @@ func TestCompileWithArchivesAndLongPaths(t *testing.T) { require.NoError(t, err) // Init the environment explicitly - _, _, err = cli.Run("update") + _, _, err = cli.Run("update", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Install core to compile - _, _, err = cli.Run("core", "install", "esp8266:esp8266@2.7.4") + _, _, err = cli.Run("core", "install", "esp8266:esp8266@2.7.4", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Install test library - _, _, err = cli.Run("lib", "install", "ArduinoIoTCloud") + _, _, err = cli.Run("lib", "install", "ArduinoIoTCloud", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - stdout, _, err := cli.Run("lib", "examples", "ArduinoIoTCloud", "--format", "json") + stdout, _, err := cli.Run("lib", "examples", "ArduinoIoTCloud", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) var libOutput []map[string]interface{} err = json.Unmarshal(stdout, &libOutput) @@ -858,7 +863,7 @@ func TestCompileWithArchivesAndLongPaths(t *testing.T) { sketchPath := paths.New(libOutput[0]["library"].(map[string]interface{})["install_dir"].(string)) sketchPath = sketchPath.Join("examples", "ArduinoIoTCloud-Advanced") - _, _, err = cli.Run("compile", "-b", "esp8266:esp8266:huzzah", sketchPath.String()) + _, _, err = cli.Run("compile", "-b", "esp8266:esp8266:huzzah", sketchPath.String(), "--config-file", "arduino-cli.yaml") require.NoError(t, err) } @@ -908,16 +913,19 @@ func TestCompileWithFullyPrecompiledLibrary(t *testing.T) { // https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries wd, err := paths.Getwd() require.NoError(t, err) - _, _, err = cli.Run("lib", "install", "--zip-path", wd.Parent().Join("testdata", "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip").String()) + _, _, err = cli.Run("lib", "install", + "--zip-path", wd.Parent().Join("testdata", "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip").String(), + "--config-file", "arduino-cli.yaml", + ) require.NoError(t, err) sketchFolder := cli.SketchbookDir().Join("libraries", "Arduino_TensorFlowLite", "examples", "hello_world") // Install example dependency - _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1") + _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Compile and verify dependencies detection for fully precompiled library is skipped - stdout, _, err := cli.Run("compile", "-b", fqbn, sketchFolder.String(), "-v") + stdout, _, err := cli.Run("compile", "-b", fqbn, "--config-file", "arduino-cli.yaml", sketchFolder.String(), "-v") require.NoError(t, err) require.Contains(t, string(stdout), "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite") } diff --git a/internal/integrationtest/config/config_test.go b/internal/integrationtest/config/config_test.go index b9f96878feb..ab098960498 100644 --- a/internal/integrationtest/config/config_test.go +++ b/internal/integrationtest/config/config_test.go @@ -288,19 +288,19 @@ func TestAddRemoveSetDeleteOnUnexistingKey(t *testing.T) { _, _, err := cli.Run("config", "init", "--dest-dir", ".") require.NoError(t, err) - _, stderr, err := cli.Run("config", "add", "some.key", "some_value") + _, stderr, err := cli.Run("config", "add", "some.key", "some_value", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "Settings key doesn't exist") - _, stderr, err = cli.Run("config", "remove", "some.key", "some_value") + _, stderr, err = cli.Run("config", "remove", "some.key", "some_value", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "Settings key doesn't exist") - _, stderr, err = cli.Run("config", "set", "some.key", "some_value") + _, stderr, err = cli.Run("config", "set", "some.key", "some_value", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "Settings key doesn't exist") - _, stderr, err = cli.Run("config", "delete", "some.key") + _, stderr, err = cli.Run("config", "delete", "some.key", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "Settings key doesn't exist") } @@ -314,26 +314,28 @@ func TestAddSingleArgument(t *testing.T) { require.NoError(t, err) // Verifies no additional urls are present - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") // Adds one URL url := "https://example.com" - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", url) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", url, "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies URL has been saved - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") // Adds the same URL (should not error) - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", url) + _, _, err = cli.Run("config", "add", + "board_manager.additional_urls", url, + "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies a second copy has NOT been added - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") } @@ -347,7 +349,7 @@ func TestAddMultipleArguments(t *testing.T) { require.NoError(t, err) // Verifies no additional urls are present - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") @@ -356,11 +358,13 @@ func TestAddMultipleArguments(t *testing.T) { "https://example.com/package_example_index.json", "https://example.com/yet_another_package_example_index.json", } - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "add", + "board_manager.additional_urls", urls[0], urls[1], + "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies URL has been saved - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -374,11 +378,11 @@ func TestAddMultipleArguments(t *testing.T) { }`) // Adds both the same URLs a second time - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies no change in result array - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -397,11 +401,11 @@ func TestAddMultipleArguments(t *testing.T) { "https://example.com/a_third_package_example_index.json", "https://example.com/yet_another_package_example_index.json", } - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1], urls[2]) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1], urls[2], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies URL has been saved - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "3") requirejson.Contains(t, stdout, ` @@ -425,17 +429,17 @@ func TestAddOnUnsupportedKey(t *testing.T) { require.NoError(t, err) // Verifies default value - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") // Tries and fails to add a new item - _, stderr, err := cli.Run("config", "add", "daemon.port", "50000") + _, stderr, err := cli.Run("config", "add", "daemon.port", "50000", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "The key 'daemon.port' is not a list of items, can't add to it.\nMaybe use 'config set'?") // Verifies value is not changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") } @@ -453,11 +457,11 @@ func TestRemoveSingleArgument(t *testing.T) { "https://example.com/package_example_index.json", "https://example.com/yet_another_package_example_index.json", } - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -471,11 +475,11 @@ func TestRemoveSingleArgument(t *testing.T) { }`) // Remove first URL - _, _, err = cli.Run("config", "remove", "board_manager.additional_urls", urls[0]) + _, _, err = cli.Run("config", "remove", "board_manager.additional_urls", urls[0], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies URLs has been removed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") } @@ -493,11 +497,11 @@ func TestRemoveMultipleArguments(t *testing.T) { "https://example.com/package_example_index.json", "https://example.com/yet_another_package_example_index.json", } - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -511,11 +515,11 @@ func TestRemoveMultipleArguments(t *testing.T) { }`) // Remove all URLs - _, _, err = cli.Run("config", "remove", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "remove", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies all URLs have been removed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") } @@ -529,17 +533,17 @@ func TestRemoveOnUnsupportedKey(t *testing.T) { require.NoError(t, err) // Verifies default value - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") // Tries and fails to remove an item - _, stderr, err := cli.Run("config", "remove", "daemon.port", "50051") + _, stderr, err := cli.Run("config", "remove", "daemon.port", "50051", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "The key 'daemon.port' is not a list of items, can't remove from it.\nMaybe use 'config delete'?") // Verifies value is not changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") } @@ -553,27 +557,27 @@ func TestSetSliceWithSingleArgument(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") // Set an URL in the list url := "https://example.com/package_example_index.json" - _, _, err = cli.Run("config", "set", "board_manager.additional_urls", url) + _, _, err = cli.Run("config", "set", "board_manager.additional_urls", url, "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/package_example_index.json\"]") // Set an URL in the list url = "https://example.com/yet_another_package_example_index.json" - _, _, err = cli.Run("config", "set", "board_manager.additional_urls", url) + _, _, err = cli.Run("config", "set", "board_manager.additional_urls", url, "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") } @@ -587,7 +591,7 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") @@ -596,11 +600,11 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { "https://example.com/first_package_index.json", "https://example.com/second_package_index.json", } - _, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -618,11 +622,11 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { "https://example.com/third_package_index.json", "https://example.com/fourth_package_index.json", } - _, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1]) + _, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1], "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies previous value is overwritten - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` @@ -645,11 +649,14 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { "https://example.com/sixth_package_index.json", "https://example.com/first_package_index.json", } - _, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1], urls[2], urls[3], urls[4], urls[5], urls[6]) + _, _, err = cli.Run("config", + "set", + "board_manager.additional_urls", urls[0], urls[1], urls[2], urls[3], urls[4], urls[5], urls[6], + "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies all unique values exist in config - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "4") requirejson.Contains(t, stdout, ` @@ -674,16 +681,16 @@ func TestSetStringWithSingleArgument(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".logging | .level", "\"info\"") // Changes value - _, _, err = cli.Run("config", "set", "logging.level", "trace") + _, _, err = cli.Run("config", "set", "logging.level", "trace", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".logging | .level", "\"trace\"") } @@ -697,7 +704,7 @@ func TestSetStringWithMultipleArguments(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".logging | .level", "\"info\"") @@ -716,16 +723,16 @@ func TestSetBoolWithSingleArgument(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") // Changes value - _, _, err = cli.Run("config", "set", "library.enable_unsafe_install", "true") + _, _, err = cli.Run("config", "set", "library.enable_unsafe_install", "true", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is changed - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "true") } @@ -739,12 +746,12 @@ func TestSetBoolWithMultipleArguments(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") // Changes value - _, stderr, err := cli.Run("config", "set", "library.enable_unsafe_install", "true", "foo") + _, stderr, err := cli.Run("config", "set", "library.enable_unsafe_install", "true", "foo", "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "Can't set multiple values in key library.enable_unsafe_install") } @@ -758,12 +765,12 @@ func TestDelete(t *testing.T) { require.NoError(t, err) // Verifies default state - stdout, _, err := cli.Run("config", "dump", "--format", "json") + stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") // Delete config key - _, _, err = cli.Run("config", "delete", "library.enable_unsafe_install") + _, _, err = cli.Run("config", "delete", "library.enable_unsafe_install", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is not found, we read directly from file instead of using @@ -775,12 +782,12 @@ func TestDelete(t *testing.T) { require.NotContains(t, configLines, "enable_unsafe_install") // Verifies default state - stdout, _, err = cli.Run("config", "dump", "--format", "json") + stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") // Delete config key and sub keys - _, _, err = cli.Run("config", "delete", "board_manager") + _, _, err = cli.Run("config", "delete", "board_manager", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies value is not found, we read directly from file instead of using diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index ff522a714a5..9bb8b95c092 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -963,12 +963,12 @@ func TestCoreIndexWithoutChecksum(t *testing.T) { _, _, err := cli.Run("config", "init", "--dest-dir", ".") require.NoError(t, err) url := "https://raw.githubusercontent.com/keyboardio/ArduinoCore-GD32-Keyboardio/ae5938af2f485910729e7d27aa233032a1cb4734/package_gd32_index.json" // noqa: E501 - _, _, err = cli.Run("config", "add", "board_manager.additional_urls", url) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", url, "--config-file", "arduino-cli.yaml") require.NoError(t, err) - _, _, err = cli.Run("core", "update-index") + _, _, err = cli.Run("core", "update-index", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - _, _, err = cli.Run("core", "list", "--all") + _, _, err = cli.Run("core", "list", "--all", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // this should not make the cli crash } diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index 8cbae1af5de..f1e14eac9c2 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -620,7 +620,7 @@ func TestInstallWithGitUrl(t *testing.T) { gitUrl := "https://github.com/arduino-libraries/WiFi101.git" // Test git-url library install - stdout, _, err := cli.Run("lib", "install", "--git-url", gitUrl) + stdout, _, err := cli.Run("lib", "install", "--git-url", gitUrl, "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.Contains(t, string(stdout), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.") @@ -628,7 +628,7 @@ func TestInstallWithGitUrl(t *testing.T) { require.DirExists(t, libInstallDir.String()) // Reinstall library - _, _, err = cli.Run("lib", "install", "--git-url", gitUrl) + _, _, err = cli.Run("lib", "install", "--git-url", gitUrl, "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies library remains installed @@ -652,16 +652,16 @@ func TestInstallWithGitUrlFragmentAsBranch(t *testing.T) { gitUrl := "https://github.com/arduino-libraries/WiFi101.git" // Test that a bad ref fails - _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#x-ref-does-not-exist") + _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#x-ref-does-not-exist", "--config-file", "arduino-cli.yaml") require.Error(t, err) // Verifies library is installed in expected path - _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#0.16.0") + _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#0.16.0", "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.DirExists(t, libInstallDir.String()) // Reinstall library at an existing ref - _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#master") + _, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#master", "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies library remains installed @@ -1129,7 +1129,7 @@ func TestInstallZipLibWithMacosMetadata(t *testing.T) { zipPath, err := paths.New("..", "testdata", "fake-lib.zip").Abs() require.NoError(t, err) // Test zip-path install - stdout, _, err := cli.Run("lib", "install", "--zip-path", zipPath.String()) + stdout, _, err := cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.Contains(t, string(stdout), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.") @@ -1139,7 +1139,9 @@ func TestInstallZipLibWithMacosMetadata(t *testing.T) { require.FileExists(t, libInstallDir.Join("src", "fake-lib.h").String()) // Reinstall library - _, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String()) + _, _, err = cli.Run("lib", "install", + "--zip-path", zipPath.String(), + "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies library remains installed @@ -1165,7 +1167,7 @@ func TestInstallZipInvalidLibrary(t *testing.T) { zipPath, err := paths.New("..", "testdata", "lib-without-header.zip").Abs() require.NoError(t, err) // Test zip-path install - _, stderr, err := cli.Run("lib", "install", "--zip-path", zipPath.String()) + _, stderr, err := cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "library not valid") @@ -1176,7 +1178,7 @@ func TestInstallZipInvalidLibrary(t *testing.T) { zipPath, err = paths.New("..", "testdata", "lib-without-properties.zip").Abs() require.NoError(t, err) // Test zip-path install - _, stderr, err = cli.Run("lib", "install", "--zip-path", zipPath.String()) + _, stderr, err = cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "library not valid") } @@ -1211,7 +1213,7 @@ func TestInstallGitInvalidLibrary(t *testing.T) { // Verifies library is not already installed require.NoDirExists(t, libInstallDir.String()) - _, stderr, err := cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String()) + _, stderr, err := cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String(), "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "library not valid") require.NoDirExists(t, libInstallDir.String()) @@ -1237,7 +1239,7 @@ func TestInstallGitInvalidLibrary(t *testing.T) { // Verifies library is not already installed require.NoDirExists(t, libInstallDir.String()) - _, stderr, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String()) + _, stderr, err = cli.RunWithCustomEnv(envVar, "lib", "install", "--git-url", repoDir.String(), "--config-file", "arduino-cli.yaml") require.Error(t, err) require.Contains(t, string(stderr), "library not valid") require.NoDirExists(t, libInstallDir.String()) @@ -1358,11 +1360,11 @@ func TestInstallGitUrlAndZipPathFlagsVisibility(t *testing.T) { _, _, err = cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".") require.NoError(t, err) - stdout, _, err = cli.Run("lib", "install", "--git-url", gitUrl) + stdout, _, err = cli.Run("lib", "install", "--git-url", gitUrl, "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.Contains(t, string(stdout), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.") - stdout, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String()) + stdout, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.Contains(t, string(stdout), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.") } @@ -1389,7 +1391,7 @@ func TestInstallWithZipPath(t *testing.T) { require.NoDirExists(t, libInstallDir.String()) // Test zip-path install - stdout, _, err := cli.Run("lib", "install", "--zip-path", zipPath.String()) + stdout, _, err := cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.NoError(t, err) require.Contains(t, string(stdout), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.") @@ -1405,7 +1407,7 @@ func TestInstallWithZipPath(t *testing.T) { require.Contains(t, files, libInstallDir.Join("README.adoc")) // Reinstall library - _, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String()) + _, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", "arduino-cli.yaml") require.NoError(t, err) // Verifies library remains installed diff --git a/main.go b/main.go index 4063632a42d..55f139c5ca1 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( ) func main() { - configuration.Settings = configuration.Init(configuration.FindConfigFileInArgsOrWorkingDirectory(os.Args)) + configuration.Settings = configuration.Init(configuration.FindConfigFileInArgs(os.Args)) i18n.Init(configuration.Settings.GetString("locale")) arduinoCmd := cli.NewCommand() if err := arduinoCmd.Execute(); err != nil {