Skip to content

Improve output message with config file creation #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}