Open weshouman opened 8 months ago
86d2fcc2ce
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the sandbox execution logs prior to making any changes:
db53f81
Checking internal/integrationtest/config/config_test.go for syntax errors... ✅ internal/integrationtest/config/config_test.go has no syntax errors!
1/1 ✓Checking internal/integrationtest/config/config_test.go for syntax errors... ✅ internal/integrationtest/config/config_test.go has no syntax errors!
Sandbox passed on the latest master
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
internal/integrationtest/config/config_test.go
✓ https://github.com/weshouman/arduino-cli/commit/06a68475f6627854464088b5921732e24c92b309 Edit
Modify internal/integrationtest/config/config_test.go with contents:
• Add a new test function to test the `ARDUINO_CONFIG` environment variable.
• In the new test function, set the `ARDUINO_CONFIG` environment variable to a test configuration file.
• Run the `config init` command and check that the configuration file used is the one set in the `ARDUINO_CONFIG` environment variable.
• This can be done by checking the output of the `config init` command or by checking the configuration file directly.
• Make sure to clean up the environment variable after the test to avoid affecting other tests.
--- +++ @@ -772,6 +772,32 @@ require.Contains(t, string(stderr), "Can't set multiple values in key library.enable_unsafe_install") } +func TestARDUINO_CONFIGEnvVar(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + // Set ARDUINO_CONFIG environment variable + testConfigFile := "test-config.yaml" + require.NoError(t, os.Setenv("ARDUINO_CONFIG", testConfigFile)) + defer func() { require.NoError(t, os.Unsetenv("ARDUINO_CONFIG")) }() + + // Run config init command + _, stderr, err := cli.Run("config", "init") + require.Empty(t, stderr) + require.NoError(t, err) + + // Check that the test configuration file is used + require.FileExists(t, testConfigFile) + + // Read the configuration file and make sure it's not empty + testConfig, err := ioutil.ReadFile(testConfigFile) + require.NoError(t, err) + require.NotEmpty(t, testConfig) + + // To avoid false positives, check that specific configurations are present + require.Contains(t, string(testConfig), "board_manager") +} + func TestDelete(t *testing.T) { env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) defer env.CleanUp()
internal/integrationtest/config/config_test.go
✓ Edit
Check internal/integrationtest/config/config_test.go with contents:
Ran GitHub Actions for 06a68475f6627854464088b5921732e24c92b309:
docs/configuration.md
✓ https://github.com/weshouman/arduino-cli/commit/81c1d5e8bccc83b6d14a15cb8ec86068c474025c Edit
Modify docs/configuration.md with contents:
• Add a new section to the documentation to describe the `ARDUINO_CONFIG` environment variable.
• Explain that the `ARDUINO_CONFIG` environment variable can be used to set the configuration file.
• Provide examples of how to set the `ARDUINO_CONFIG` environment variable on different operating systems.
• Mention that the `ARDUINO_CONFIG` environment variable is checked before the `--config-file` flag and the auto checking of the current and parent directories.
--- +++ @@ -74,11 +74,33 @@ ### Environment variables +The `ARDUINO_CONFIG` environment variable sets the configuration file that Arduino CLI uses. It is checked before the `--config-file` command line flag and the automatic checking of the current and parent directories. + All configuration options can be set via environment variables. The variable names start with `ARDUINO`, followed by the configuration key names, with each component separated by `_`. For example, the `ARDUINO_DIRECTORIES_USER` environment variable sets the `directories.user` configuration option. -On Linux or macOS, you can use the [`export` command][export command] to set environment variables. On Windows cmd, you +On Linux or macOS, you can use the [`export` command][export command] to set environment variables, for example: + +```sh +$ export ARDUINO_CONFIG=/path/to/config.yaml +``` + +On Windows cmd, you can use the [`set` command][set command] to achieve the same, for example: + +```cmd +> set ARDUINO_CONFIG=C:\path\to\config.yaml +``` + +On Windows PowerShell, use the `$env:` method, for example: + +```powershell +> $env:ARDUINO_CONFIG="C:\path\to\config.yaml" +``` + +After setting the `ARDUINO_CONFIG` environment variable, the specified configuration file is used for all subsequent Arduino CLI commands. + +On Linux or macOS, you can use the [`set` command][set command]. `ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS` environment variables can be a list of space-separated URLs.
docs/configuration.md
✓ Edit
Check docs/configuration.md with contents:
Ran GitHub Actions for 81c1d5e8bccc83b6d14a15cb8ec86068c474025c:
I have finished reviewing the code for completeness. I did not find errors for sweep/support_arduino_config_environment_varia
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
The Environment Variables section could be split to the section for configuring ARDUINO_CONFIG (the new section) and section for other configurations (the previously defined one)
This is superfluous
On Linux or macOS, you
can use the [`set` command][set command].
Only the test is supported, the implementation itself is yet to be supported
Describe the request
Is it possible to support setting the configuration file using an environment variable?
Currently it's possible to set the config file through multiple ways, like
--config-file
and by auto checking the current and parent directories. However, using an environment variable to ensure all the upcoming commands will be using the correct config file would ensure consistency and confidence in the result.Note, as a current workaround, I'm shadowing the arduino-cli command using the following bash function, which indeed works, but it's not a clean solution.
Describe the current behavior
No environment variable are mentioned in the documentation that would set the --config-file
Arduino CLI version
Version: 0.34.2
Operating system
Linux
Operating system version
Any
Additional context
No response
Issue checklist
Checklist
- [X] Modify `internal/integrationtest/config/config_test.go` ✓ https://github.com/weshouman/arduino-cli/commit/06a68475f6627854464088b5921732e24c92b309 [Edit](https://github.com/weshouman/arduino-cli/edit/sweep/support_arduino_config_environment_varia/internal/integrationtest/config/config_test.go#L27-L35) - [X] Running GitHub Actions for `internal/integrationtest/config/config_test.go` ✓ [Edit](https://github.com/weshouman/arduino-cli/edit/sweep/support_arduino_config_environment_varia/internal/integrationtest/config/config_test.go#L27-L35) - [X] Modify `docs/configuration.md` ✓ https://github.com/weshouman/arduino-cli/commit/81c1d5e8bccc83b6d14a15cb8ec86068c474025c [Edit](https://github.com/weshouman/arduino-cli/edit/sweep/support_arduino_config_environment_varia/docs/configuration.md#L77-L98) - [X] Running GitHub Actions for `docs/configuration.md` ✓ [Edit](https://github.com/weshouman/arduino-cli/edit/sweep/support_arduino_config_environment_varia/docs/configuration.md#L77-L98)