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

Commit

Permalink
add helpers package to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 16, 2020
1 parent dc24b4d commit 9a0e23e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
5 changes: 3 additions & 2 deletions internal/commands/envcmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/martinnirtl/dockma/internal/survey"
"github.com/martinnirtl/dockma/internal/utils"
"github.com/martinnirtl/dockma/internal/utils/helpers"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/ttacon/chalk"
Expand All @@ -20,9 +21,9 @@ var removeCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
env := ""
if len(args) == 0 {
env = utils.GetEnvironment("")
env = helpers.GetEnvironment("")
} else {
env = utils.GetEnvironment(args[0])
env = helpers.GetEnvironment(args[0])
}

sure := survey.Confirm(fmt.Sprintf("Are you sure to remove '%s'", env), false)
Expand Down
5 changes: 3 additions & 2 deletions internal/commands/envcmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/martinnirtl/dockma/internal/utils"
"github.com/martinnirtl/dockma/internal/utils/helpers"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/ttacon/chalk"
Expand All @@ -18,9 +19,9 @@ var setCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
env := ""
if len(args) == 0 {
env = utils.GetEnvironment("")
env = helpers.GetEnvironment("")
} else {
env = utils.GetEnvironment(args[0])
env = helpers.GetEnvironment(args[0])
}

activeEnv := viper.GetString("active")
Expand Down
26 changes: 26 additions & 0 deletions internal/utils/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package helpers

import (
"fmt"

"github.com/martinnirtl/dockma/internal/config"
"github.com/martinnirtl/dockma/internal/survey"
"github.com/ttacon/chalk"
)

// GetEnvironment returns one environment
func GetEnvironment(env string) string {
envs := config.GetEnvNames()

for _, envName := range envs {
if env == envName {
return env
}
}

fmt.Printf("%sNo such environment: %s%s\n", chalk.Yellow, env, chalk.ResetColor)

env = survey.Select("Choose an environment", envs)

return env
}
19 changes: 0 additions & 19 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"os"

"github.com/martinnirtl/dockma/internal/config"
"github.com/martinnirtl/dockma/internal/survey"
"github.com/ttacon/chalk"
)

Expand Down Expand Up @@ -54,23 +52,6 @@ func NoEnvs() {
os.Exit(0)
}

// GetEnvironment returns one environment
func GetEnvironment(env string) string {
envs := config.GetEnvNames()

for _, envName := range envs {
if env == envName {
return env
}
}

fmt.Printf("%sNo such environment: %s%s\n", chalk.Yellow, env, chalk.ResetColor)

env = survey.Select("Choose an environment", envs)

return env
}

// Fallback returns fallback if val is nil
func Fallback(val string, fallback string) string {
if val == "" {
Expand Down

0 comments on commit 9a0e23e

Please sign in to comment.