Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit553b7be

Browse files
author
Massimiliano Pippi
authored
add option --dest-dir to config init, removed noop --save-as (#575)
1 parent28875e6 commit553b7be

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

‎cli/config/init.go‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import (
2626
"github.com/spf13/viper"
2727
)
2828

29+
vardestDirstring
30+
31+
constdefaultFileName="arduino-cli.yaml"
32+
2933
funcinitInitCommand()*cobra.Command {
3034
initCommand:=&cobra.Command{
3135
Use:"init",
@@ -37,31 +41,28 @@ func initInitCommand() *cobra.Command {
3741
Args:cobra.NoArgs,
3842
Run:runInitCommand,
3943
}
40-
initCommand.Flags().StringVar(&initFlags.location,"save-as","",
41-
"Sets where to save the configuration file [default is ./arduino-cli.yaml].")
44+
initCommand.Flags().StringVar(&destDir,"dest-dir","","Sets where to save the configuration file.")
4245
returninitCommand
4346
}
4447

45-
varinitFlagsstruct {
46-
locationstring// The custom location of the file to create.
47-
}
48-
4948
funcrunInitCommand(cmd*cobra.Command,args []string) {
50-
logrus.Info("Executing `arduino config init`")
49+
ifdestDir=="" {
50+
destDir=viper.GetString("directories.Data")
51+
}
52+
logrus.Infof("Writing config file to: %s",destDir)
5153

52-
dataDir:=viper.GetString("directories.Data")
53-
iferr:=os.MkdirAll(dataDir,os.FileMode(0755));err!=nil {
54-
feedback.Errorf("Cannot create data directory: %v",err)
54+
iferr:=os.MkdirAll(destDir,os.FileMode(0755));err!=nil {
55+
feedback.Errorf("Cannot create config file directory: %v",err)
5556
os.Exit(errorcodes.ErrGeneric)
5657
}
5758

58-
configFile:=filepath.Join(dataDir,"arduino-cli.yaml")
59-
err:=viper.WriteConfigAs(configFile)
60-
iferr!=nil {
59+
configFile:=filepath.Join(destDir,defaultFileName)
60+
iferr:=viper.WriteConfigAs(configFile);err!=nil {
6161
feedback.Errorf("Cannot create config file: %v",err)
6262
os.Exit(errorcodes.ErrGeneric)
6363
}
6464

65-
feedback.Print("Config file written: "+configFile)
66-
logrus.Info("Done")
65+
msg:="Config file written to: "+configFile
66+
logrus.Info(msg)
67+
feedback.Print(msg)
6768
}

‎test/test_config.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to license@arduino.cc.
15+
importos
16+
17+
18+
deftest_init(run_command,data_dir,working_dir):
19+
result=run_command("config init")
20+
assertresult.ok
21+
assertdata_dirinresult.stdout
22+
23+
24+
deftest_init_dest(run_command,working_dir):
25+
dest=os.path.join(working_dir,"config","test")
26+
result=run_command("config init --dest-dir "+dest)
27+
assertresult.ok
28+
assertdestinresult.stdout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp