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
553b7be3
Unverified
Commit
553b7be3
authored
Feb 11, 2020
by
Massimiliano Pippi
Committed by
GitHub
Feb 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option --dest-dir to config init, removed noop --save-as (#575)
parent
28875e6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
15 deletions
+44
-15
cli/config/init.go
cli/config/init.go
+16
-15
test/test_config.py
test/test_config.py
+28
-0
No files found.
cli/config/init.go
View file @
553b7be3
...
...
@@ -26,6 +26,10 @@ import (
"github.com/spf13/viper"
)
var
destDir
string
const
defaultFileName
=
"arduino-cli.yaml"
func
initInitCommand
()
*
cobra
.
Command
{
initCommand
:=
&
cobra
.
Command
{
Use
:
"init"
,
...
...
@@ -37,31 +41,28 @@ func initInitCommand() *cobra.Command {
Args
:
cobra
.
NoArgs
,
Run
:
runInitCommand
,
}
initCommand
.
Flags
()
.
StringVar
(
&
initFlags
.
location
,
"save-as"
,
""
,
"Sets where to save the configuration file [default is ./arduino-cli.yaml]."
)
initCommand
.
Flags
()
.
StringVar
(
&
destDir
,
"dest-dir"
,
""
,
"Sets where to save the configuration file."
)
return
initCommand
}
var
initFlags
struct
{
location
string
// The custom location of the file to create.
}
func
runInitCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino config init`"
)
if
destDir
==
""
{
destDir
=
viper
.
GetString
(
"directories.Data"
)
}
logrus
.
Infof
(
"Writing config file to: %s"
,
destDir
)
dataDir
:=
viper
.
GetString
(
"directories.Data"
)
if
err
:=
os
.
MkdirAll
(
dataDir
,
os
.
FileMode
(
0755
));
err
!=
nil
{
feedback
.
Errorf
(
"Cannot create data directory: %v"
,
err
)
if
err
:=
os
.
MkdirAll
(
destDir
,
os
.
FileMode
(
0755
));
err
!=
nil
{
feedback
.
Errorf
(
"Cannot create config file directory: %v"
,
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
configFile
:=
filepath
.
Join
(
dataDir
,
"arduino-cli.yaml"
)
err
:=
viper
.
WriteConfigAs
(
configFile
)
if
err
!=
nil
{
configFile
:=
filepath
.
Join
(
destDir
,
defaultFileName
)
if
err
:=
viper
.
WriteConfigAs
(
configFile
);
err
!=
nil
{
feedback
.
Errorf
(
"Cannot create config file: %v"
,
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
feedback
.
Print
(
"Config file written: "
+
configFile
)
logrus
.
Info
(
"Done"
)
msg
:=
"Config file written to: "
+
configFile
logrus
.
Info
(
msg
)
feedback
.
Print
(
msg
)
}
test/test_config.py
0 → 100644
View file @
553b7be3
# This file is part of arduino-cli.
#
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
#
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
import
os
def
test_init
(
run_command
,
data_dir
,
working_dir
):
result
=
run_command
(
"config init"
)
assert
result
.
ok
assert
data_dir
in
result
.
stdout
def
test_init_dest
(
run_command
,
working_dir
):
dest
=
os
.
path
.
join
(
working_dir
,
"config"
,
"test"
)
result
=
run_command
(
"config init --dest-dir "
+
dest
)
assert
result
.
ok
assert
dest
in
result
.
stdout
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