diff --git a/cmd/shell.go b/cmd/shell.go index da227d15..9cbf9a28 100644 --- a/cmd/shell.go +++ b/cmd/shell.go @@ -23,7 +23,9 @@ var shellCmd = &cobra.Command{ var shellRequest *pkg.ShellRequest var err error - if strings.TrimSpace(organizationName) != "" || strings.TrimSpace(projectName) != "" || strings.TrimSpace(environmentName) != "" || strings.TrimSpace(serviceName) != "" { + if contextString != "" { + shellRequest, err = shellRequestWithContextString() + } else if strings.TrimSpace(organizationName) != "" || strings.TrimSpace(projectName) != "" || strings.TrimSpace(environmentName) != "" || strings.TrimSpace(serviceName) != "" { if strings.TrimSpace(organizationName) == "" { utils.PrintlnError(errors.New("organization name is required")) return @@ -60,8 +62,23 @@ var ( command []string podName string podContainerName string + contextString string ) +func shellRequestWithContextString() (*pkg.ShellRequest, error) { + parts := strings.Split(contextString, ":") + if len(parts) != 4 { + return nil, errors.New("context must be in format organization:project:environment:service") + } + + organizationName = parts[0] + projectName = parts[1] + environmentName = parts[2] + serviceName = parts[3] + + return shellRequestWithContextFlags() +} + func shellRequestWithContextFlags() (*pkg.ShellRequest, error) { tokenType, token, err := utils.GetAccessToken() if err != nil { @@ -348,8 +365,11 @@ func init() { shellCmd.Flags().StringVarP(&serviceName, "service", "", "", "Service Name") shellCmd.Flags().StringVarP(&podName, "pod", "p", "", "pod name where to exec into") shellCmd.Flags().StringVar(&podContainerName, "container", "", "container name inside the pod") + shellCmd.Flags().StringVarP(&contextString, "context", "", "", "Context in format organization:project:environment:service") shellCmd.Example = "qovery shell\n" + "qovery shell \n" + + "qovery shell --context :::\n" + + "qovery shell -c --context :::\n" + "qovery shell --organization --project --environment --service \n" + "qovery shell --organization --project --environment --service --pod --container --command "