From 7a0a2b1c83e57aba9605478befde86546ae85832 Mon Sep 17 00:00:00 2001 From: Prashidha Rawal <89299485+Prashidha0O1@users.noreply.github.com> Date: Sat, 15 Mar 2025 10:56:18 +0545 Subject: [PATCH] feat: able to specify the context inline on a command, updated code shell.go --- cmd/shell.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 "