Skip to content

Commit

Permalink
init: Ensure homepath is created (#51)
Browse files Browse the repository at this point in the history
Ensures that the path that holds the configuration file which will be
created already exists.

Resolves #46

Signed-off-by: Marc Lopez <[email protected]>
  • Loading branch information
marclop authored Nov 15, 2019
1 parent a4eb0ac commit 8d72808
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cmd

import (
"os"
"path/filepath"
"runtime"
"strings"
Expand All @@ -35,15 +36,18 @@ var initCmd = &cobra.Command{
PreRunE: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
fp := strings.Replace(ecctlHomePath, homePrefix, cmdutil.GetHomePath(runtime.GOOS), 1)
fp = filepath.Join(fp, defaultViper.GetString("config"))
if err := os.MkdirAll(fp, 0664); err != nil {
return err
}

return ecctl.InitConfig(ecctl.InitConfigParams{
Client: defaultClient,
Viper: defaultViper,
Reader: defaultInput,
Writer: defaultOutput,
ErrWriter: defaultError,
PasswordReadFunc: terminal.ReadPassword,
FilePath: fp,
FilePath: filepath.Join(fp, defaultViper.GetString("config")),
})
},
}
Expand Down

0 comments on commit 8d72808

Please sign in to comment.