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

Commit

Permalink
rename autopull config field to pull
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 9, 2020
1 parent 8f89a56 commit 4a0aa76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions internal/commands/envcmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ var initCmd = &cobra.Command{
os.Exit(0)
}

autoPull := "off"
pull := "off"
if _, err := os.Stat(".git"); os.IsExist(err) {
autoPull = survey.Select(fmt.Sprintf("Run %sgit pull%s before %sdockma up%s", chalk.Cyan, chalk.Reset, chalk.Cyan, chalk.ResetColor), []string{"auto", "optional", "manual", "off"})
pull = survey.Select(fmt.Sprintf("Run %sgit pull%s before %sdockma up%s", chalk.Cyan, chalk.Reset, chalk.Cyan, chalk.ResetColor), []string{"auto", "optional", "manual", "off"})
}

proceed := survey.Confirm(fmt.Sprintf("Add new environment %s%s%s (location: %s)", chalk.Cyan, env, chalk.ResetColor, workingDir), true)
Expand All @@ -60,7 +60,7 @@ var initCmd = &cobra.Command{
}

viper.Set(fmt.Sprintf("envs.%s.home", env), workingDir)
viper.Set(fmt.Sprintf("envs.%s.autopull", env), autoPull)
viper.Set(fmt.Sprintf("envs.%s.pull", env), pull)

oldEnv := viper.GetString("active")

Expand Down
20 changes: 10 additions & 10 deletions internal/commands/upcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ var UpCommand = &cobra.Command{

envHomeDir := viper.GetString(fmt.Sprintf("envs.%s.home", activeEnv))

autoPull := config.GetAutoPullSetting(activeEnv)
pull := config.GetAutoPullSetting(activeEnv)

var pull bool
switch autoPull {
var doPull bool
switch pull {
case "auto":
pull = true
doPull = true
case "optional":
pull = survey.Confirm("Pull changes from git", false)
doPull = survey.Confirm("Pull changes from git", false)
case "manual":
timePassed, err := config.GetDurationPassedSinceLastUpdate(activeEnv)

if err != nil {
pull = survey.Confirm(fmt.Sprintf("Environment never got updated (%s). Wanna pull now", utils.PrintCyan("dockma env pull")), true)
doPull = survey.Confirm(fmt.Sprintf("Environment never got updated (%s). Wanna pull now", utils.PrintCyan("dockma env pull")), true)
} else if timePassed.Hours() > 24*7 {
pull = survey.Confirm("Some time has passed since last git pull. Wanna pull now", true)
doPull = survey.Confirm("Some time has passed since last git pull. Wanna pull now", true)
}
case "off":
pull = false
doPull = false
default:
pull = false
doPull = false
}

if pull {
if doPull {
err := envcmd.Pull(envHomeDir, false)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func GetDurationPassedSinceLastUpdate(envName string) (time.Duration, error) {

// GetAutoPullSetting returns wether to run git pull or not.
func GetAutoPullSetting(envName string) string {
return viper.GetString(fmt.Sprintf("envs.%s.autopull", envName))
return viper.GetString(fmt.Sprintf("envs.%s.pull", envName))
}

// GetProfilesNames returns profile names for given env.
Expand Down

0 comments on commit 4a0aa76

Please sign in to comment.