diff --git a/cmd/deploy.go b/cmd/deploy.go index 75becd29..c8b771e4 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -171,6 +171,9 @@ This environment should already exist in lagoon. It is analogous with the 'Deplo } buildVarStrings, err := cmd.Flags().GetStringArray("buildvar") + if err != nil { + return err + } if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil { return err } diff --git a/cmd/get.go b/cmd/get.go index d4b9d936..bcccbe8c 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -2,13 +2,11 @@ package cmd import ( "context" - "encoding/json" "fmt" "strconv" "strings" "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/uselagoon/lagoon-cli/pkg/output" "github.com/uselagoon/machinery/api/lagoon" @@ -22,19 +20,6 @@ type GetFlags struct { RemoteID string `json:"remoteid,omitempty"` } -func parseGetFlags(flags pflag.FlagSet) GetFlags { - configMap := make(map[string]interface{}) - flags.VisitAll(func(f *pflag.Flag) { - if flags.Changed(f.Name) { - configMap[f.Name] = f.Value - } - }) - jsonStr, _ := json.Marshal(configMap) - parsedFlags := GetFlags{} - json.Unmarshal(jsonStr, &parsedFlags) - return parsedFlags -} - var getCmd = &cobra.Command{ Use: "get", Aliases: []string{"g"}, @@ -216,6 +201,9 @@ var getEnvironmentCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil { return err } diff --git a/cmd/groups.go b/cmd/groups.go index 57a5184a..b1ac7c39 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "encoding/json" "fmt" "slices" "strings" @@ -13,23 +12,9 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/uselagoon/lagoon-cli/pkg/api" "github.com/uselagoon/lagoon-cli/pkg/output" ) -func parseGroup(flags pflag.FlagSet) api.Group { - configMap := make(map[string]interface{}) - flags.VisitAll(func(f *pflag.Flag) { - if flags.Changed(f.Name) { - configMap[f.Name] = f.Value - } - }) - jsonStr, _ := json.Marshal(configMap) - parsedFlags := api.Group{} - json.Unmarshal(jsonStr, &parsedFlags) - return parsedFlags -} - var addGroupCmd = &cobra.Command{ Use: "group", Aliases: []string{"g"}, @@ -191,6 +176,9 @@ var addProjectToGroupCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } groupName, err := cmd.Flags().GetString("name") if err != nil { return err @@ -220,6 +208,9 @@ var addProjectToGroupCmd = &cobra.Command{ debug) project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc) + if err != nil { + return err + } if len(project.Name) == 0 { outputOptions.Error = fmt.Sprintf("Project '%s' not found", cmdProjectName) output.RenderError(outputOptions.Error, outputOptions) @@ -247,6 +238,9 @@ var deleteUserFromGroupCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } groupName, err := cmd.Flags().GetString("name") if err != nil { return err @@ -301,6 +295,9 @@ var deleteProjectFromGroupCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } groupName, err := cmd.Flags().GetString("name") if err != nil { return err @@ -330,6 +327,9 @@ var deleteProjectFromGroupCmd = &cobra.Command{ debug) project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc) + if err != nil { + return err + } if len(project.Name) == 0 { outputOptions.Error = fmt.Sprintf("Project '%s' not found", cmdProjectName) output.RenderError(outputOptions.Error, outputOptions) @@ -356,6 +356,9 @@ var deleteGroupCmd = &cobra.Command{ Short: "Delete a group from lagoon", RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } groupName, err := cmd.Flags().GetString("name") if err != nil { return err diff --git a/cmd/list.go b/cmd/list.go index 11b94005..ee8f126a 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -248,10 +248,10 @@ var listGroupProjectsCmd = &cobra.Command{ for _, project := range group.Projects { data = append(data, []string{ returnNonEmptyString(fmt.Sprintf("%d", project.ID)), - returnNonEmptyString(fmt.Sprintf("%s", project.Name)), + returnNonEmptyString(project.Name), }) if listAllProjects { - data[idx] = append(data[idx], returnNonEmptyString(fmt.Sprintf("%s", group.Name))) + data[idx] = append(data[idx], returnNonEmptyString(group.Name)) } idx++ } @@ -262,6 +262,8 @@ var listGroupProjectsCmd = &cobra.Command{ } else { outputOptions.Error = "There are no projects in any groups\n" } + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } dataMain := output.Table{ @@ -307,6 +309,8 @@ var listEnvironmentsCmd = &cobra.Command{ if len(*environments) == 0 { outputOptions.Error = fmt.Sprintf("No environments found for project '%s'\n", cmdProjectName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } data := []output.Data{} @@ -403,6 +407,8 @@ var listVariablesCmd = &cobra.Command{ } else { outputOptions.Error = fmt.Sprintf("There are no variables for project '%s'\n", cmdProjectName) } + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } output.RenderOutput(output.Table{ Header: header, @@ -462,6 +468,8 @@ var listDeploymentsCmd = &cobra.Command{ if len(data) == 0 { outputOptions.Error = fmt.Sprintf("There are no deployments for environment '%s' in project '%s'\n", cmdProjectEnvironment, cmdProjectName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } dataMain := output.Table{ Header: []string{"ID", "RemoteID", "Name", "Status", "Created", "Started", "Completed"}, @@ -523,6 +531,8 @@ var listTasksCmd = &cobra.Command{ if len(data) == 0 { outputOptions.Error = fmt.Sprintf("There are no tasks for environment '%s' in project '%s'\n", cmdProjectEnvironment, cmdProjectName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } dataMain := output.Table{ Header: []string{"ID", "RemoteID", "Name", "Status", "Created", "Started", "Completed", "Service"}, @@ -740,13 +750,15 @@ var listInvokableTasks = &cobra.Command{ data := []output.Data{} for _, task := range tasks.AdvancedTasks { data = append(data, []string{ - returnNonEmptyString(fmt.Sprintf("%s", task.Name)), - returnNonEmptyString(fmt.Sprintf("%s", task.Description)), + returnNonEmptyString(task.Name), + returnNonEmptyString(task.Description), }) } if len(data) == 0 { outputOptions.Error = "There are no user defined tasks for this environment\n" + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } dataMain := output.Table{ Header: []string{"Task Name", "Description"}, @@ -797,6 +809,8 @@ var listProjectGroupsCmd = &cobra.Command{ if len(projectGroups.Groups) == 0 { outputOptions.Error = fmt.Sprintf("There are no groups for project '%s'\n", cmdProjectName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } data := []output.Data{} @@ -863,6 +877,8 @@ var listOrganizationProjectsCmd = &cobra.Command{ if len(*orgProjects) == 0 { outputOptions.Error = fmt.Sprintf("No associated projects found for organization '%s'\n", organizationName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } data := []output.Data{} @@ -924,6 +940,8 @@ var listOrganizationGroupsCmd = &cobra.Command{ } if len(*orgGroups) == 0 { outputOptions.Error = fmt.Sprintf("No associated groups found for organization '%s'\n", organizationName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } data := []output.Data{} @@ -982,6 +1000,8 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ } if len(*deployTargets) == 0 { outputOptions.Error = fmt.Sprintf("No associated deploy targets found for organization '%s'\n", organizationName) + output.RenderOutput(output.Table{Data: []output.Data{[]string{}}}, outputOptions) + return nil } data := []output.Data{} diff --git a/cmd/root.go b/cmd/root.go index a6ba8492..8378b5de 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,8 +18,6 @@ import ( "github.com/uselagoon/lagoon-cli/pkg/app" "github.com/uselagoon/lagoon-cli/pkg/graphql" "github.com/uselagoon/lagoon-cli/pkg/lagoon/environments" - "github.com/uselagoon/lagoon-cli/pkg/lagoon/projects" - "github.com/uselagoon/lagoon-cli/pkg/lagoon/users" "github.com/uselagoon/lagoon-cli/pkg/output" "github.com/uselagoon/lagoon-cli/pkg/updatecheck" ) @@ -286,8 +284,6 @@ func Prompt(prompt string) string { // global the clients var eClient environments.Client -var uClient users.Client -var pClient projects.Client // FormatType . type FormatType string @@ -319,16 +315,6 @@ func validateToken(lagoon string) { output.RenderError(err.Error(), outputOptions) os.Exit(1) } - uClient, err = users.New(&lagoonCLIConfig, debugEnable) - if err != nil { - output.RenderError(err.Error(), outputOptions) - os.Exit(1) - } - pClient, err = projects.New(&lagoonCLIConfig, debugEnable) - if err != nil { - output.RenderError(err.Error(), outputOptions) - os.Exit(1) - } outputOptions.Debug = debugEnable } @@ -353,16 +339,6 @@ func validateTokenE(lagoon string) error { output.RenderError(err.Error(), outputOptions) return err } - uClient, err = users.New(&lagoonCLIConfig, debugEnable) - if err != nil { - output.RenderError(err.Error(), outputOptions) - return err - } - pClient, err = projects.New(&lagoonCLIConfig, debugEnable) - if err != nil { - output.RenderError(err.Error(), outputOptions) - return err - } outputOptions.Debug = debugEnable // fallback if token is expired or there was no token to begin with return nil diff --git a/cmd/shared.go b/cmd/shared.go index 4de49463..2cc479d1 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -17,13 +17,6 @@ var lagoonUI string var lagoonKibana string var lagoonSSHKey string -// user vars -var userFirstName string -var userLastName string -var userEmail string -var pubKeyFile string -var sshKeyName string - // group vars var groupName string diff --git a/cmd/tasks.go b/cmd/tasks.go index bd3b1053..c624775d 100644 --- a/cmd/tasks.go +++ b/cmd/tasks.go @@ -354,9 +354,14 @@ Path: Command: taskCommand, Service: taskService, } - fmt.Println(task.Name) project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc) + if err != nil { + return err + } environment, err := lagoon.GetEnvironmentByName(context.TODO(), cmdProjectEnvironment, project.ID, lc) + if err != nil { + return err + } taskResult, err := lagoon.AddTask(context.TODO(), environment.ID, task, lc) if err != nil { return err diff --git a/cmd/users.go b/cmd/users.go index 588eedd5..4947e945 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "encoding/json" "fmt" "os" "strconv" @@ -13,26 +12,9 @@ import ( "github.com/uselagoon/machinery/api/schema" "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/uselagoon/lagoon-cli/pkg/api" "github.com/uselagoon/lagoon-cli/pkg/output" ) -func parseUser(flags pflag.FlagSet) api.User { - configMap := make(map[string]interface{}) - flags.VisitAll(func(f *pflag.Flag) { - if flags.Changed(f.Name) { - configMap[f.Name] = f.Value - } - }) - jsonStr, _ := json.Marshal(configMap) - parsedFlags := api.User{} - json.Unmarshal(jsonStr, &parsedFlags) - // lowercase user email address - parsedFlags.Email = strings.ToLower(parsedFlags.Email) - return parsedFlags -} - func parseSSHKeyFile(sshPubKey string, keyName string, keyValue string, userEmail string) (schema.AddSSHKeyInput, error) { // if we haven't got a keyvalue if keyValue == "" {