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
7d00b5be
Unverified
Commit
7d00b5be
authored
Jun 18, 2024
by
Cristian Maglie
Committed by
GitHub
Jun 18, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix regression: setting 3rd party URL via ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS env var (#2645)
parent
55753bdd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
internal/cli/configuration/defaults.go
internal/cli/configuration/defaults.go
+1
-1
internal/go-configmap/cli.go
internal/go-configmap/cli.go
+38
-1
internal/integrationtest/config/config_test.go
internal/integrationtest/config/config_test.go
+29
-0
No files found.
internal/cli/configuration/defaults.go
View file @
7d00b5be
...
...
@@ -84,7 +84,7 @@ func InjectEnvVars(settings *Settings) {
// Bind env aliases to keep backward compatibility
setIfEnvExists
:=
func
(
key
,
env
string
)
{
if
v
,
ok
:=
os
.
LookupEnv
(
env
);
ok
{
settings
.
SetFrom
CLIArgs
(
key
,
v
)
settings
.
SetFrom
ENV
(
key
,
v
)
}
}
setIfEnvExists
(
"library.enable_unsafe_install"
,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL"
)
...
...
internal/go-configmap/cli.go
View file @
7d00b5be
...
...
@@ -21,6 +21,43 @@ import (
"strings"
)
func
(
c
*
Map
)
SetFromENV
(
key
string
,
arg
string
)
error
{
// in case of schemaless configuration, we don't know the type of the setting
// we will save it as a string
if
len
(
c
.
schema
)
==
0
{
c
.
Set
(
key
,
arg
)
return
nil
}
// Find the correct type for the given setting
valueType
,
ok
:=
c
.
schema
[
key
]
if
!
ok
{
return
fmt
.
Errorf
(
"key not found: %s"
,
key
)
}
var
value
any
{
var
conversionError
error
switch
valueType
.
String
()
{
case
"uint"
:
value
,
conversionError
=
strconv
.
Atoi
(
arg
)
case
"bool"
:
value
,
conversionError
=
strconv
.
ParseBool
(
arg
)
case
"string"
:
value
=
arg
case
"[]string"
:
value
=
strings
.
Split
(
arg
,
" "
)
default
:
return
fmt
.
Errorf
(
"unhandled type: %s"
,
valueType
)
}
if
conversionError
!=
nil
{
return
fmt
.
Errorf
(
"error setting value: %v"
,
conversionError
)
}
}
return
c
.
Set
(
key
,
value
)
}
func
(
c
*
Map
)
SetFromCLIArgs
(
key
string
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
c
.
Delete
(
key
)
...
...
@@ -101,7 +138,7 @@ func (c *Map) InjectEnvVars(env []string, prefix string) []error {
}
// Update the configuration value
if
err
:=
c
.
SetFrom
CLIArgs
(
key
,
envValue
);
err
!=
nil
{
if
err
:=
c
.
SetFrom
ENV
(
key
,
envValue
);
err
!=
nil
{
errs
=
append
(
errs
,
err
)
}
}
...
...
internal/integrationtest/config/config_test.go
View file @
7d00b5be
...
...
@@ -902,3 +902,32 @@ build.unk: 123
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"en"
,
strings
.
TrimSpace
(
string
(
out
)))
}
func
TestConfigViaEnvVars
(
t
*
testing
.
T
)
{
env
,
cli
:=
integrationtest
.
CreateArduinoCLIWithEnvironment
(
t
)
defer
env
.
CleanUp
()
// array of strings
out
,
_
,
err
:=
cli
.
RunWithCustomEnv
(
map
[
string
]
string
{
"ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS"
:
"https://espressif.github.io/arduino-esp32/package_esp32_index.json https://arduino.esp8266.com/stable/package_esp8266com_index.json"
},
"config"
,
"get"
,
"board_manager.additional_urls"
,
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"- https://espressif.github.io/arduino-esp32/package_esp32_index.json
\n
- https://arduino.esp8266.com/stable/package_esp8266com_index.json
\n\n
"
,
string
(
out
))
// boolean
out
,
_
,
err
=
cli
.
RunWithCustomEnv
(
map
[
string
]
string
{
"ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL"
:
"True"
},
"config"
,
"get"
,
"library.enable_unsafe_install"
,
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"true
\n\n
"
,
string
(
out
))
// integer
out
,
_
,
err
=
cli
.
RunWithCustomEnv
(
map
[
string
]
string
{
"ARDUINO_BUILD_CACHE_COMPILATIONS_BEFORE_PURGE"
:
"20"
},
"config"
,
"get"
,
"build_cache.compilations_before_purge"
,
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"20
\n\n
"
,
string
(
out
))
}
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