@@ -26,6 +26,10 @@ import (
2626 "github.com/spf13/viper"
2727)
2828
29+ var destDir string
30+
31+ const defaultFileName = "arduino-cli.yaml"
32+
2933func initInitCommand () * 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 return initCommand
4346}
4447
45- var initFlags struct {
46- location string // The custom location of the file to create.
47- }
48-
4948func 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 )
5153
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 )
5556 os .Exit (errorcodes .ErrGeneric )
5657 }
5758
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 {
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}
0 commit comments