@@ -26,6 +26,10 @@ import (
26
26
"github.com/spf13/viper"
27
27
)
28
28
29
+ var destDir string
30
+
31
+ const defaultFileName = "arduino-cli.yaml"
32
+
29
33
func initInitCommand () * cobra.Command {
30
34
initCommand := & cobra.Command {
31
35
Use : "init" ,
@@ -37,31 +41,28 @@ func initInitCommand() *cobra.Command {
37
41
Args : cobra .NoArgs ,
38
42
Run : runInitCommand ,
39
43
}
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." )
42
45
return initCommand
43
46
}
44
47
45
- var initFlags struct {
46
- location string // The custom location of the file to create.
47
- }
48
-
49
48
func runInitCommand (cmd * cobra.Command , args []string ) {
50
- logrus .Info ("Executing `arduino config init`" )
49
+ if destDir == "" {
50
+ destDir = viper .GetString ("directories.Data" )
51
+ }
52
+ logrus .Infof ("Writing config file to: %s" , destDir )
51
53
52
- dataDir := viper .GetString ("directories.Data" )
53
- if err := os .MkdirAll (dataDir , os .FileMode (0755 )); err != nil {
54
- feedback .Errorf ("Cannot create data directory: %v" , err )
54
+ if err := os .MkdirAll (destDir , os .FileMode (0755 )); err != nil {
55
+ feedback .Errorf ("Cannot create config file directory: %v" , err )
55
56
os .Exit (errorcodes .ErrGeneric )
56
57
}
57
58
58
- configFile := filepath .Join (dataDir , "arduino-cli.yaml" )
59
- err := viper .WriteConfigAs (configFile )
60
- if err != nil {
59
+ configFile := filepath .Join (destDir , defaultFileName )
60
+ if err := viper .WriteConfigAs (configFile ); err != nil {
61
61
feedback .Errorf ("Cannot create config file: %v" , err )
62
62
os .Exit (errorcodes .ErrGeneric )
63
63
}
64
64
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 )
67
68
}
0 commit comments