From dc3a16c64f8028cea0ac2e96f6fcd518abd7f9bd Mon Sep 17 00:00:00 2001 From: Alexander Neishkasha Date: Wed, 15 Jan 2020 22:50:05 +0200 Subject: [PATCH] add getting env from input if argument is not setted --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6700277..f8be93b 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/joho/godotenv" "log" "os" @@ -10,7 +11,8 @@ func main() { if err := godotenv.Load(); err != nil { log.Fatal("Error loading .env file") } - env := os.Args[1] + env := getEnv() + fmt.Println("Connecting...") awsFacade := AwsFacade{region: os.Getenv("AWS_DEFAULT_REGION"), env: env} ip, err := awsFacade.IP() if err != nil { @@ -19,3 +21,13 @@ func main() { ssh := SshFacade{ip, env} ssh.Connect() } + +func getEnv() string { + if len(os.Args) > 1 { + return os.Args[1] + } + var env string + fmt.Printf("Enter the name of environment (stg/prod): ") + fmt.Scanln(&env) + return env +}