Skip to content

Commit 8d72808

Browse files
authored
init: Ensure homepath is created (#51)
Ensures that the path that holds the configuration file which will be created already exists. Resolves #46 Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent a4eb0ac commit 8d72808

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/init.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package cmd
1919

2020
import (
21+
"os"
2122
"path/filepath"
2223
"runtime"
2324
"strings"
@@ -35,15 +36,18 @@ var initCmd = &cobra.Command{
3536
PreRunE: cobra.MaximumNArgs(0),
3637
RunE: func(cmd *cobra.Command, args []string) error {
3738
fp := strings.Replace(ecctlHomePath, homePrefix, cmdutil.GetHomePath(runtime.GOOS), 1)
38-
fp = filepath.Join(fp, defaultViper.GetString("config"))
39+
if err := os.MkdirAll(fp, 0664); err != nil {
40+
return err
41+
}
42+
3943
return ecctl.InitConfig(ecctl.InitConfigParams{
4044
Client: defaultClient,
4145
Viper: defaultViper,
4246
Reader: defaultInput,
4347
Writer: defaultOutput,
4448
ErrWriter: defaultError,
4549
PasswordReadFunc: terminal.ReadPassword,
46-
FilePath: fp,
50+
FilePath: filepath.Join(fp, defaultViper.GetString("config")),
4751
})
4852
},
4953
}

0 commit comments

Comments
 (0)