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
04536776
Commit
04536776
authored
Apr 22, 2024
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use custom type to avoid context-values collisions
parent
4c50868a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
5 deletions
+21
-5
internal/cli/cli.go
internal/cli/cli.go
+1
-1
internal/cli/config/config.go
internal/cli/config/config.go
+17
-1
internal/cli/config/init.go
internal/cli/config/init.go
+1
-1
main.go
main.go
+2
-2
No files found.
internal/cli/cli.go
View file @
04536776
...
...
@@ -117,7 +117,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
preRun
(
verbose
,
outputFormat
,
logLevel
,
logFile
,
logFormat
,
noColor
,
settings
)
// Log the configuration file used
if
configFile
:=
c
tx
.
Value
(
"config_file"
)
.
(
string
);
configFile
!=
""
{
if
configFile
:=
c
onfig
.
GetConfigFile
(
ctx
);
configFile
!=
""
{
logrus
.
Infof
(
"Using config file: %s"
,
configFile
)
}
else
{
logrus
.
Info
(
"Config file not found, using default values"
)
...
...
internal/cli/config/config.go
View file @
04536776
...
...
@@ -64,6 +64,22 @@ func getAllArraySettingsKeys(ctx context.Context, srv rpc.ArduinoCoreServiceServ
return
arrayKeys
}
type
ctxValue
string
// GetConfigFile returns the configuration file path from the context
func
GetConfigFile
(
ctx
context
.
Context
)
string
{
res
:=
ctx
.
Value
(
ctxValue
(
"config_file"
))
if
res
==
nil
{
return
""
}
return
res
.
(
string
)
}
// SetConfigFile sets the configuration file path in the context
func
SetConfigFile
(
ctx
context
.
Context
,
configFile
string
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
ctxValue
(
"config_file"
),
configFile
)
}
func
saveConfiguration
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
var
outConfig
[]
byte
if
res
,
err
:=
srv
.
ConfigurationSave
(
ctx
,
&
rpc
.
ConfigurationSaveRequest
{
SettingsFormat
:
"yaml"
});
err
!=
nil
{
...
...
@@ -72,7 +88,7 @@ func saveConfiguration(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
outConfig
=
[]
byte
(
res
.
GetEncodedSettings
())
}
configFile
:=
ctx
.
Value
(
"config_file"
)
.
(
string
)
configFile
:=
GetConfigFile
(
ctx
)
if
err
:=
paths
.
New
(
configFile
)
.
WriteFile
(
outConfig
);
err
!=
nil
{
feedback
.
Fatal
(
tr
(
"Error writing to file: %v"
,
err
),
feedback
.
ErrGeneric
)
}
...
...
internal/cli/config/init.go
View file @
04536776
...
...
@@ -83,7 +83,7 @@ func runInitCommand(srv rpc.ArduinoCoreServiceServer) {
configFileAbsPath
=
configFileDir
.
Join
(
defaultFileName
)
default
:
configFileAbsPath
=
paths
.
New
(
ctx
.
Value
(
"config_file"
)
.
(
string
))
configFileAbsPath
=
paths
.
New
(
GetConfigFile
(
ctx
))
configFileDir
=
configFileAbsPath
.
Parent
()
}
...
...
main.go
View file @
04536776
...
...
@@ -22,6 +22,7 @@ import (
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/internal/cli"
"github.com/arduino/arduino-cli/internal/cli/config"
"github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/internal/i18n"
...
...
@@ -35,8 +36,7 @@ func main() {
// Search for the configuration file in the command line arguments and in the environment
configFile
:=
configuration
.
FindConfigFileInArgsFallbackOnEnv
(
os
.
Args
)
ctx
:=
context
.
Background
()
ctx
=
context
.
WithValue
(
ctx
,
"config_file"
,
configFile
)
ctx
:=
config
.
SetConfigFile
(
context
.
Background
(),
configFile
)
// Read the settings from the configuration file
openReq
:=
&
rpc
.
ConfigurationOpenRequest
{
SettingsFormat
:
"yaml"
}
...
...
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