Skip to content
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)
}