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

Commit

Permalink
rename envscmd to envcmd pkg and add pullCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 9, 2020
1 parent 2039990 commit c7b1d5b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package envscmd
package envcmd

import (
"errors"
Expand Down Expand Up @@ -48,7 +48,10 @@ var initCmd = &cobra.Command{
os.Exit(0)
}

autoPull := survey.Confirm(fmt.Sprintf("Run %sgit pull%s before %sdockma up%s", chalk.Cyan, chalk.Reset, chalk.Cyan, chalk.ResetColor), false)
autoPull := "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"})
}

proceed := survey.Confirm(fmt.Sprintf("Add new environment %s%s%s (location: %s)", chalk.Cyan, env, chalk.ResetColor, workingDir), true)

Expand All @@ -74,5 +77,5 @@ var initCmd = &cobra.Command{
}

func init() {
EnvsCommand.AddCommand(initCmd)
EnvCommand.AddCommand(initCmd)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package envscmd
package envcmd

import (
"fmt"
Expand Down Expand Up @@ -36,5 +36,5 @@ var listCmd = &cobra.Command{
}

func init() {
EnvsCommand.AddCommand(listCmd)
EnvCommand.AddCommand(listCmd)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pullcmd
package envcmd

import (
"errors"
Expand All @@ -14,6 +14,33 @@ import (
"github.com/ttacon/chalk"
)

var pullCommand = &cobra.Command{
Use: "pull",
Short: "Run 'git pull' in active environment home dir.",
Long: "Run 'git pull' in active environment home dir.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {

activeEnv := config.GetActiveEnv()

if activeEnv == "-" {
utils.NoEnvs()
}

envHomeDir := config.GetEnvHomeDir(activeEnv)

err := Pull(envHomeDir, true)

utils.Error(err)

utils.Success(fmt.Sprintf("Successfully pulled env: %s", activeEnv))
},
}

func init() {
EnvCommand.AddCommand(pullCommand)
}

// Pull runs git pull in given path and optionally logs output
func Pull(path string, log bool) error {
err := os.Chdir(path)
Expand All @@ -38,27 +65,7 @@ func Pull(path string, log bool) error {
return errors.New("Could not execute 'git pull' in active environment home dir")
}

return nil
}

// PullCommand implements the top level pull command
var PullCommand = &cobra.Command{
Use: "pull",
Short: "Run 'git pull' in active environment home dir.",
Long: "Run 'git pull' in active environment home dir.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {

activeEnv := config.GetActiveEnv()

if activeEnv == "-" {
utils.NoEnvs()
}

envHomeDir := config.GetEnvHomeDir(activeEnv)
// config.SetEnvUpdated() // TODO make config to object

err := Pull(envHomeDir, true)

utils.Error(err)
},
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package envscmd
package envcmd

import (
"fmt"
Expand Down Expand Up @@ -56,5 +56,5 @@ var removeCmd = &cobra.Command{
}

func init() {
EnvsCommand.AddCommand(removeCmd)
EnvCommand.AddCommand(removeCmd)
}
1 change: 1 addition & 0 deletions internal/commands/envcmd/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package envcmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package envscmd
package envcmd

import (
"github.com/spf13/cobra"
)

// EnvsCommand implements the top level envs command
var EnvsCommand = &cobra.Command{
// EnvCommand implements the top level envs command
var EnvCommand = &cobra.Command{
Use: "env",
Aliases: []string{"environment"},
Short: "Environments reflect docker-compose based projects.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package envscmd
package envcmd

import (
"fmt"
Expand Down Expand Up @@ -42,5 +42,5 @@ var setCmd = &cobra.Command{
}

func init() {
EnvsCommand.AddCommand(setCmd)
EnvCommand.AddCommand(setCmd)
}
1 change: 0 additions & 1 deletion internal/commands/envscmd/rename.go

This file was deleted.

8 changes: 3 additions & 5 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (

"github.com/martinnirtl/dockma/internal/commands/configcmd"
"github.com/martinnirtl/dockma/internal/commands/downcmd"
"github.com/martinnirtl/dockma/internal/commands/envscmd"
"github.com/martinnirtl/dockma/internal/commands/envcmd"
"github.com/martinnirtl/dockma/internal/commands/initcmd"
"github.com/martinnirtl/dockma/internal/commands/inspectcmd"
"github.com/martinnirtl/dockma/internal/commands/logscmd"
"github.com/martinnirtl/dockma/internal/commands/profilecmd"
"github.com/martinnirtl/dockma/internal/commands/pscmd"
"github.com/martinnirtl/dockma/internal/commands/pullcmd"
"github.com/martinnirtl/dockma/internal/commands/upcmd"
"github.com/martinnirtl/dockma/internal/commands/versioncmd"
"github.com/mitchellh/go-homedir"
Expand All @@ -35,13 +34,12 @@ var RootCommand = &cobra.Command{
func init() {
RootCommand.AddCommand(configcmd.ConfigCommand)
RootCommand.AddCommand(downcmd.DownCommand)
RootCommand.AddCommand(envscmd.EnvsCommand)
RootCommand.AddCommand(envcmd.EnvCommand)
RootCommand.AddCommand(initcmd.InitCommand)
RootCommand.AddCommand(inspectcmd.InspectCommand)
RootCommand.AddCommand(logscmd.LogsCommand)
RootCommand.AddCommand(profilecmd.ProfileCommand)
RootCommand.AddCommand(pscmd.PSCommand)
RootCommand.AddCommand(pullcmd.PullCommand)
RootCommand.AddCommand(upcmd.UpCommand)
RootCommand.AddCommand(versioncmd.VersionCommand)

Expand All @@ -65,7 +63,7 @@ func init() {
}

viper.SetDefault("username", "User")
viper.SetDefault("hidesubcommandoutput", false)
viper.SetDefault("hidesubcommandoutput", true)
viper.SetDefault("logfile", "log.txt")
viper.SetDefault("active", "-")
viper.SetDefault("envs", map[string]interface{}{})
Expand Down

0 comments on commit c7b1d5b

Please sign in to comment.