diff --git a/cmd/get.go b/cmd/get.go index d2ead230..bd7b97c4 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -169,6 +169,7 @@ var getToken = &cobra.Command{ }, } +// TODO - update once the API is updated var getOrganizationCmd = &cobra.Command{ Use: "organization", Aliases: []string{"o"}, @@ -181,7 +182,7 @@ var getOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationID, err := cmd.Flags().GetInt("org") + organizationID, err := cmd.Flags().GetUint("id") if err != nil { return err } @@ -199,14 +200,14 @@ var getOrganizationCmd = &cobra.Command{ organization, err := l.GetOrganizationByID(context.TODO(), organizationID, lc) handleError(err) - if organization == nil { + if organization.Name == "" { output.RenderInfo(fmt.Sprintf("No organization found for ID '%d'", organizationID), outputOptions) os.Exit(0) } data := []output.Data{} data = append(data, []string{ - strconv.Itoa(organizationID), + strconv.Itoa(int(organizationID)), organization.Name, organization.Description, strconv.Itoa(int(organization.QuotaProject)), @@ -238,5 +239,5 @@ func init() { getTaskByID.Flags().BoolP("logs", "L", false, "Show the task logs if available") getProjectKeyCmd.Flags().BoolVarP(&revealValue, "reveal", "", false, "Reveal the variable values") getDeploymentCmd.Flags().StringVarP(&remoteID, "remoteid", "R", "", "The remote ID of the deployment") - getOrganizationCmd.Flags().Int("org", 0, "ID of the organization") + getOrganizationCmd.Flags().Uint("id", 0, "ID of the organization") } diff --git a/cmd/organization.go b/cmd/organization.go index 7c31d0f2..378ab1cf 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -69,7 +69,7 @@ var deleteOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - organizationId, err := cmd.Flags().GetInt("id") + organizationId, err := cmd.Flags().GetUint("id") if err != nil { return err } @@ -101,7 +101,62 @@ var deleteOrganizationCmd = &cobra.Command{ }, } +// TODO - update once the API is updated +var updateOrganizationCmd = &cobra.Command{ + Use: "organization", + Aliases: []string{"o"}, + Short: "Update an organization", + PreRunE: func(_ *cobra.Command, _ []string) error { + return validateTokenE(lagoonCLIConfig.Current) + }, + RunE: func(cmd *cobra.Command, args []string) error { + debug, err := cmd.Flags().GetBool("debug") + if err != nil { + return err + } + organizationId, err := cmd.Flags().GetUint("id") + if err != nil { + return err + } + description, err := cmd.Flags().GetString("description") + if err != nil { + return err + } + + if organizationId == 0 { + fmt.Println("Missing arguments: Organization ID is not defined") + cmd.Help() + os.Exit(1) + } + + current := lagoonCLIConfig.Current + token := lagoonCLIConfig.Lagoons[current].Token + lc := lclient.New( + lagoonCLIConfig.Lagoons[current].GraphQL, + lagoonCLIVersion, + &token, + debug) + + organizationFlags := s.UpdateOrganizationPatchInput{ + Description: description, + } + result, err := l.UpdateOrganization(context.TODO(), organizationId, organizationFlags, lc) + handleError(err) + + resultData := output.Result{ + Result: "success", + ResultData: map[string]interface{}{ + "Organization Name": result.Name, + }, + } + output.RenderResult(resultData, outputOptions) + return nil + }, +} + func init() { + updateOrganizationCmd.Flags().Uint("id", 0, "ID of the organization to update") + updateOrganizationCmd.Flags().StringP("description", "d", "", "Description of the organization") addOrganizationCmd.Flags().String("name", "", "Name of the organization") - deleteOrganizationCmd.Flags().Int("id", 0, "ID of the organization") + deleteOrganizationCmd.Flags().Uint("id", 0, "ID of the organization") } diff --git a/cmd/update.go b/cmd/update.go index 68a23ff7..12106614 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -29,4 +29,5 @@ func init() { updateCmd.AddCommand(updateUserCmd) updateCmd.AddCommand(updateDeployTargetConfigCmd) updateCmd.AddCommand(updateDeployTargetCmd) + updateCmd.AddCommand(updateOrganizationCmd) } diff --git a/go.mod b/go.mod index 4ec1069e..eaf36fc2 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/guregu/null v4.0.0+incompatible // workaround for https://github.com/manifoldco/promptui/issues/98 github.com/nicksnyder/go-i18n v1.10.1 // indirect - github.com/uselagoon/machinery v0.0.11 + github.com/uselagoon/machinery v0.0.12-0.20230928085239-eaa5a60c02b6 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect @@ -39,6 +39,6 @@ require ( // use this version for fixes to formatting of end header replace github.com/olekukonko/tablewriter => github.com/shreddedbacon/tablewriter v0.0.2-0.20200114082015-d810c4a558bf -// replace github.com/machinebox/graphql => ../../shreddedbacon/graphql +//replace github.com/uselagoon/machinery => ../machinery -// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter \ No newline at end of file +// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter