Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
95753fcc
Unverified
Commit
95753fcc
authored
Jan 04, 2024
by
Alessio Perugini
Committed by
GitHub
Jan 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to specify the config file through `ARDUINO_CONFIG_FILE` env (#2488)
parent
cdbf2f5e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
12 deletions
+61
-12
docs/configuration.md
docs/configuration.md
+1
-0
internal/cli/configuration/configuration.go
internal/cli/configuration/configuration.go
+5
-4
internal/cli/configuration/configuration_test.go
internal/cli/configuration/configuration_test.go
+12
-4
internal/docsgen/main.go
internal/docsgen/main.go
+1
-1
internal/integrationtest/config/config_test.go
internal/integrationtest/config/config_test.go
+39
-0
internal/integrationtest/monitor/monitor_grpc_test.go
internal/integrationtest/monitor/monitor_grpc_test.go
+2
-2
main.go
main.go
+1
-1
No files found.
docs/configuration.md
View file @
95753fcc
...
...
@@ -127,6 +127,7 @@ 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.
Location specified by the
`ARDUINO_CONFIG_FILE`
environment variable
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
...
...
internal/cli/configuration/configuration.go
View file @
95753fcc
...
...
@@ -133,9 +133,10 @@ func GetDefaultBuiltinLibrariesDir() string {
return
filepath
.
Join
(
getDefaultArduinoDataDir
(),
"libraries"
)
}
// FindConfigFileInArgs returns the config file path using the
// argument '--config-file' (if specified) or looking in the current working dir
func
FindConfigFileInArgs
(
args
[]
string
)
string
{
// FindConfigFileInArgsFallbackOnEnv returns the config file path using the
// argument '--config-file' (if specified), if empty looks for the ARDUINO_CONFIG_FILE env,
// or looking in the current working dir
func
FindConfigFileInArgsFallbackOnEnv
(
args
[]
string
)
string
{
// Look for '--config-file' argument
for
i
,
arg
:=
range
args
{
if
arg
==
"--config-file"
{
...
...
@@ -144,5 +145,5 @@ func FindConfigFileInArgs(args []string) string {
}
}
}
return
""
return
os
.
Getenv
(
"ARDUINO_CONFIG_FILE"
)
}
internal/cli/configuration/configuration_test.go
View file @
95753fcc
...
...
@@ -60,15 +60,23 @@ func TestInit(t *testing.T) {
}
func
TestFindConfigFile
(
t
*
testing
.
T
)
{
configFile
:=
FindConfigFileInArgs
([]
string
{
"--config-file"
})
configFile
:=
FindConfigFileInArgs
FallbackOnEnv
([]
string
{
"--config-file"
})
require
.
Equal
(
t
,
""
,
configFile
)
configFile
=
FindConfigFileInArgs
([]
string
{
"--config-file"
,
"some/path/to/config"
})
configFile
=
FindConfigFileInArgs
FallbackOnEnv
([]
string
{
"--config-file"
,
"some/path/to/config"
})
require
.
Equal
(
t
,
"some/path/to/config"
,
configFile
)
configFile
=
FindConfigFileInArgs
([]
string
{
"--config-file"
,
"some/path/to/config/arduino-cli.yaml"
})
configFile
=
FindConfigFileInArgs
FallbackOnEnv
([]
string
{
"--config-file"
,
"some/path/to/config/arduino-cli.yaml"
})
require
.
Equal
(
t
,
"some/path/to/config/arduino-cli.yaml"
,
configFile
)
configFile
=
FindConfigFileInArgs
([]
string
{})
configFile
=
FindConfigFileInArgs
FallbackOnEnv
([]
string
{})
require
.
Equal
(
t
,
""
,
configFile
)
t
.
Setenv
(
"ARDUINO_CONFIG_FILE"
,
"some/path/to/config"
)
configFile
=
FindConfigFileInArgsFallbackOnEnv
([]
string
{})
require
.
Equal
(
t
,
"some/path/to/config"
,
configFile
)
// when both env and flag are specified flag takes precedence
configFile
=
FindConfigFileInArgsFallbackOnEnv
([]
string
{
"--config-file"
,
"flag/path"
})
require
.
Equal
(
t
,
"flag/path"
,
configFile
)
}
internal/docsgen/main.go
View file @
95753fcc
...
...
@@ -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
.
FindConfigFileInArgs
(
os
.
Args
))
configuration
.
Settings
=
configuration
.
Init
(
configuration
.
FindConfigFileInArgs
FallbackOnEnv
(
os
.
Args
))
cli
:=
cli
.
NewCommand
()
cli
.
DisableAutoGenTag
=
true
// Disable addition of auto-generated date stamp
err
:=
doc
.
GenMarkdownTree
(
cli
,
os
.
Args
[
1
])
...
...
internal/integrationtest/config/config_test.go
View file @
95753fcc
...
...
@@ -16,9 +16,11 @@
package
config_test
import
(
"path/filepath"
"testing"
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
"gopkg.in/yaml.v3"
...
...
@@ -815,3 +817,40 @@ func TestDelete(t *testing.T) {
require
.
NotContains
(
t
,
configLines
,
"additional_urls"
)
require
.
NotContains
(
t
,
configLines
,
"board_manager"
)
}
func
TestInitializationOrderOfConfigThroughFlagAndEnv
(
t
*
testing
.
T
)
{
env
,
cli
:=
integrationtest
.
CreateArduinoCLIWithEnvironment
(
t
)
defer
env
.
CleanUp
()
createConfig
:=
func
(
path
*
paths
.
Path
,
content
string
)
{
f
,
err
:=
path
.
Create
()
require
.
NoError
(
t
,
err
)
_
,
err
=
f
.
WriteString
(
content
)
require
.
NoError
(
t
,
err
)
}
tmp
:=
t
.
TempDir
()
cliConfig
,
envConfig
:=
paths
.
New
(
filepath
.
Join
(
tmp
,
"cli.yaml"
)),
paths
.
New
(
filepath
.
Join
(
tmp
,
"env.yaml"
))
createConfig
(
cliConfig
,
`cli-test: "test"`
)
createConfig
(
envConfig
,
`env-test: "test"`
)
// No flag nor env specified.
stdout
,
_
,
err
:=
cli
.
Run
(
"config"
,
"dump"
,
"--format"
,
"json"
)
require
.
NoError
(
t
,
err
)
requirejson
.
NotEmpty
(
t
,
stdout
)
// Flag specified
stdout
,
_
,
err
=
cli
.
Run
(
"config"
,
"dump"
,
"--config-file"
,
cliConfig
.
String
(),
"--format"
,
"json"
)
require
.
NoError
(
t
,
err
)
requirejson
.
Contains
(
t
,
stdout
,
`{"config":{ "cli-test": "test" }}`
)
// Env specified
customEnv
:=
map
[
string
]
string
{
"ARDUINO_CONFIG_FILE"
:
envConfig
.
String
()}
stdout
,
_
,
err
=
cli
.
RunWithCustomEnv
(
customEnv
,
"config"
,
"dump"
,
"--format"
,
"json"
)
require
.
NoError
(
t
,
err
)
requirejson
.
Contains
(
t
,
stdout
,
`{"config":{ "env-test": "test" }}`
)
// Flag and env specified, flag takes precedence
stdout
,
_
,
err
=
cli
.
RunWithCustomEnv
(
customEnv
,
"config"
,
"dump"
,
"--config-file"
,
cliConfig
.
String
(),
"--format"
,
"json"
)
require
.
NoError
(
t
,
err
)
requirejson
.
Contains
(
t
,
stdout
,
`{"config":{ "cli-test": "test" }}`
)
}
internal/integrationtest/monitor/monitor_grpc_test.go
View file @
95753fcc
...
...
@@ -58,7 +58,7 @@ func TestMonitorGRPCClose(t *testing.T) {
tmpFileMatcher
:=
regexp
.
MustCompile
(
"Tmpfile: (.*)
\n
"
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
3
)
mon
,
err
:=
grpcInst
.
Monitor
(
ctx
,
ports
[
0
]
.
Port
)
mon
,
err
:=
grpcInst
.
Monitor
(
ctx
,
ports
[
0
]
.
GetPort
()
)
var
tmpFile
*
paths
.
Path
for
{
monResp
,
err
:=
mon
.
Recv
()
...
...
@@ -85,7 +85,7 @@ func TestMonitorGRPCClose(t *testing.T) {
{
// Keep a timeout to allow the test to exit in any case
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
10
)
mon
,
err
:=
grpcInst
.
Monitor
(
ctx
,
ports
[
0
]
.
Port
)
mon
,
err
:=
grpcInst
.
Monitor
(
ctx
,
ports
[
0
]
.
GetPort
()
)
var
tmpFile
*
paths
.
Path
for
{
monResp
,
err
:=
mon
.
Recv
()
...
...
main.go
View file @
95753fcc
...
...
@@ -25,7 +25,7 @@ import (
)
func
main
()
{
configuration
.
Settings
=
configuration
.
Init
(
configuration
.
FindConfigFileInArgs
(
os
.
Args
))
configuration
.
Settings
=
configuration
.
Init
(
configuration
.
FindConfigFileInArgs
FallbackOnEnv
(
os
.
Args
))
i18n
.
Init
(
configuration
.
Settings
.
GetString
(
"locale"
))
arduinoCmd
:=
cli
.
NewCommand
()
if
err
:=
arduinoCmd
.
Execute
();
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment