44 "context"
55 "fmt"
66 "os"
7+ "strings"
78 "time"
89
910 "github.com/spf13/cobra"
@@ -82,9 +83,13 @@ func getSSHHostPort(environmentName string, debug bool) (string, string, string,
8283 username := fmt .Sprintf ("%s-%s" , cmdProjectName , environmentName )
8384
8485 // check all the environments for this project
85- for _ , env := range project .Environments {
86+ found := false
87+ names := make ([]string , len (project .Environments ))
88+ for i , env := range project .Environments {
89+ names [i ] = env .Name
8690 // if the env name matches the requested or computed environment then check if the deploytarget supports regional ssh endpoints
8791 if env .OpenshiftProjectName == namespace .GenerateNamespaceName ("" , cmdProjectEnvironment , cmdProjectName , "" , "" , false ) || env .Name == environmentName || env .Name == cmdProjectEnvironment {
92+ found = true
8893 // if the deploytarget supports regional endpoints, then set these as the host and port for ssh
8994 if env .DeployTarget .SSHHost != "" && env .DeployTarget .SSHPort != "" {
9095 sshHost = env .DeployTarget .SSHHost
@@ -95,6 +100,11 @@ func getSSHHostPort(environmentName string, debug bool) (string, string, string,
95100 username = env .OpenshiftProjectName
96101 }
97102 }
103+
104+ if ! found {
105+ return sshHost , sshPort , username , portal , fmt .Errorf ("invalid environment for project %s: %s. Valid options are %s.\n " , cmdProjectName , environmentName , strings .Join (names , ", " ))
106+ }
107+
98108 return sshHost , sshPort , username , portal , nil
99109}
100110
0 commit comments