Skip to content

Commit

Permalink
Improve output message with config file creation (arduino#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinay Lanka authored Apr 2, 2020
1 parent 38a80a6 commit 322bc6a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cli/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,27 @@ func runInitCommand(cmd *cobra.Command, args []string) {
if destDir == "" {
destDir = viper.GetString("directories.Data")
}
logrus.Infof("Writing config file to: %s", destDir)

if err := os.MkdirAll(destDir, os.FileMode(0755)); err != nil {
absPath, err := filepath.Abs(destDir)
if err != nil {
feedback.Errorf("Cannot find absolute path: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
configFileAbsPath := filepath.Join(absPath, defaultFileName)

logrus.Infof("Writing config file to: %s", absPath)

if err := os.MkdirAll(absPath, os.FileMode(0755)); err != nil {
feedback.Errorf("Cannot create config file directory: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

configFile := filepath.Join(destDir, defaultFileName)
if err := viper.WriteConfigAs(configFile); err != nil {
if err := viper.WriteConfigAs(configFileAbsPath); err != nil {
feedback.Errorf("Cannot create config file: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

msg := "Config file written to: " + configFile
msg := "Config file written to: " + configFileAbsPath
logrus.Info(msg)
feedback.Print(msg)
}

0 comments on commit 322bc6a

Please sign in to comment.