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

Commit

Permalink
add env home command
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Mar 2, 2020
1 parent f5fb8ae commit dfb29f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/commands/envcmd/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package envcmd

import (
"fmt"

"github.com/martinnirtl/dockma/internal/commands/argvalidators"
"github.com/martinnirtl/dockma/internal/commands/hooks"
"github.com/martinnirtl/dockma/internal/config"
"github.com/martinnirtl/dockma/internal/survey"
"github.com/martinnirtl/dockma/internal/utils"
"github.com/spf13/cobra"
)

func getHomeCommand() *cobra.Command {
return &cobra.Command{
Use: "home [environment]",
Short: "Get environment home dir",
Long: "Get environment home dir",
Example: "dockma env home",
Args: argvalidators.OptionalEnv,
PreRun: hooks.RequiresEnv,
Run: runHomeCommand,
}
}

func runHomeCommand(cmd *cobra.Command, args []string) {
activeEnv := config.GetActiveEnv()

envName := ""
if len(args) == 0 {
if activeEnv.GetName() == "-" {
envNames := config.GetEnvNames()
envName = survey.Select("Choose an environment", envNames)
} else {
envName = activeEnv.GetName()
}
} else {
envName = args[0]
}

env, err := config.GetEnv(envName)
utils.ErrorAndExit(err)

fmt.Println(env.GetHomeDir())
}
1 change: 1 addition & 0 deletions internal/commands/envcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func GetEnvCommand() *cobra.Command {
Long: "Environments reflect docker-compose based projects",
}

envCommand.AddCommand(getHomeCommand())
envCommand.AddCommand(getInitCommand())
envCommand.AddCommand(getListCommand())
envCommand.AddCommand(getPullCommand())
Expand Down

0 comments on commit dfb29f2

Please sign in to comment.