Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
clean init cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 19, 2020
1 parent 94b757d commit b81c2d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/commands/initcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"time"

"github.com/martinnirtl/dockma/internal/config"
"github.com/martinnirtl/dockma/internal/survey"
"github.com/martinnirtl/dockma/internal/utils"
"github.com/spf13/cobra"
Expand All @@ -26,14 +27,13 @@ var InitCommand = &cobra.Command{
}

func initPreRunHook(cmd *cobra.Command, args []string) {
if init := viper.GetTime("init"); !init.IsZero() {
if init := config.GetInitTime(); !init.IsZero() {
proceed := survey.Confirm(fmt.Sprintf("%sDockma CLI has already been initialized!%s Do you want to proceed", chalk.Yellow, chalk.ResetColor), false)

if !proceed {
utils.Abort()
}
} else {
accept := survey.Confirm(fmt.Sprintf("Dockma CLI config will be stored at: %s", viper.GetString("home")), true)
accept := survey.Confirm(fmt.Sprintf("Dockma CLI config will be stored at: %s", config.GetHomeDir()), true)

if !accept {
fmt.Printf("Ok, you can change the config default location by setting %sDOCKMA_HOME%s environment variable.\n", chalk.Cyan, chalk.ResetColor)
Expand All @@ -54,7 +54,7 @@ func initCommandHandler(cmd *cobra.Command, args []string) {
viper.Set("username", username)
viper.Set("init", time.Now())

home := viper.GetString("home")
home := config.GetHomeDir()

if err := os.MkdirAll(home, os.FileMode(0755)); err != nil {
utils.ErrorAndExit(fmt.Errorf("Could not create config dir: %s", err))
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func SaveNow() (successMessages []string, errorMessages []error, err error) {
return
}

// GetInitTime returns the init time.
func GetInitTime() time.Time {
return viper.GetTime("init")
}

// GetUsername returns the user's name.
func GetUsername() string {
return viper.GetString("username")
Expand Down

0 comments on commit b81c2d1

Please sign in to comment.