Skip to content

Commit

Permalink
cmd & flag cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Oct 16, 2023
1 parent bbb3db5 commit d31a6fb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
15 changes: 7 additions & 8 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ var getToken = &cobra.Command{
},
}

// TODO - update once the API is updated
var getOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Expand All @@ -182,12 +181,12 @@ var getOrganizationCmd = &cobra.Command{
if err != nil {
return err
}
organizationID, err := cmd.Flags().GetUint("id")
organizationName, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if organizationID == 0 {
return fmt.Errorf("missing arguments: Organization ID is not defined")
if organizationName == "" {
return fmt.Errorf("missing arguments: Organization is not defined")
}

current := lagoonCLIConfig.Current
Expand All @@ -197,17 +196,17 @@ var getOrganizationCmd = &cobra.Command{
lagoonCLIVersion,
&token,
debug)
organization, err := l.GetOrganizationByID(context.TODO(), organizationID, lc)
organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)

if organization.Name == "" {
output.RenderInfo(fmt.Sprintf("No organization found for ID '%d'", organizationID), outputOptions)
output.RenderInfo(fmt.Sprintf("No organization found for '%s'", organizationName), outputOptions)
os.Exit(0)
}

data := []output.Data{}
data = append(data, []string{
strconv.Itoa(int(organizationID)),
strconv.Itoa(int(organization.ID)),
organization.Name,
organization.Description,
strconv.Itoa(int(organization.QuotaProject)),
Expand Down Expand Up @@ -239,5 +238,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().Uint("id", 0, "ID of the organization")
getOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization")
}
3 changes: 1 addition & 2 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ var deleteGroupCmd = &cobra.Command{
},
}

// TODO
var addGroupToOrganizationCmd = &cobra.Command{
Use: "organization-group",
Aliases: []string{"og", "orggroup"},
Expand Down Expand Up @@ -300,6 +299,6 @@ func init() {
deleteProjectFromGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
deleteGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
addGroupToOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization")
addGroupToOrganizationCmd.Flags().StringP("group", "g", "", "Name of the group")
addGroupToOrganizationCmd.Flags().StringP("group", "G", "", "Name of the group")
addGroupToOrganizationCmd.Flags().Bool("orgOwner", false, "Flag to add the user to the group as an owner")
}
36 changes: 20 additions & 16 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ var listOrganizationProjectsCmd = &cobra.Command{
if err != nil {
return err
}
organizationID, err := cmd.Flags().GetUint("id")
if organizationID == 0 {
return fmt.Errorf("missing arguments: Organization ID is not defined")
organizationName, err := cmd.Flags().GetString("organization")
if organizationName == "" {
return fmt.Errorf("missing arguments: Organization is not defined")
}

current := lagoonCLIConfig.Current
Expand All @@ -460,7 +460,9 @@ var listOrganizationProjectsCmd = &cobra.Command{
lagoonCLIVersion,
&token,
debug)
orgProjects, err := l.ListProjectsByOrganizationID(context.TODO(), organizationID, lc)

org, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
orgProjects, err := l.ListProjectsByOrganizationID(context.TODO(), org.ID, lc)
handleError(err)

data := []output.Data{}
Expand Down Expand Up @@ -492,9 +494,9 @@ var listOrganizationGroupsCmd = &cobra.Command{
if err != nil {
return err
}
organizationID, err := cmd.Flags().GetUint("id")
if organizationID == 0 {
return fmt.Errorf("missing arguments: Organization ID is not defined")
organizationName, err := cmd.Flags().GetString("organization")
if organizationName == "" {
return fmt.Errorf("missing arguments: Organization is not defined")
}

current := lagoonCLIConfig.Current
Expand All @@ -504,7 +506,9 @@ var listOrganizationGroupsCmd = &cobra.Command{
lagoonCLIVersion,
&token,
debug)
orgGroups, err := l.ListGroupsByOrganizationID(context.TODO(), organizationID, lc)

org, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
orgGroups, err := l.ListGroupsByOrganizationID(context.TODO(), org.ID, lc)
handleError(err)

data := []output.Data{}
Expand All @@ -525,10 +529,10 @@ var listOrganizationGroupsCmd = &cobra.Command{
},
}

var listDeployTargetsByOrganizationCmd = &cobra.Command{
Use: "organization-deploytargets",
var listOrganizationDeployTargetsCmd = &cobra.Command{
Use: "organization-deploy-targets",
Aliases: []string{"odt"},
Short: "Print a list of deploytargets in an organization",
Short: "Print a list of deploy targets in an organization",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(cmdLagoon)
},
Expand Down Expand Up @@ -639,14 +643,14 @@ func init() {
listCmd.AddCommand(listDeployTargetConfigsCmd)
listCmd.AddCommand(listOrganizationProjectsCmd)
listCmd.AddCommand(listOrganizationGroupsCmd)
listCmd.AddCommand(listDeployTargetsByOrganizationCmd)
listCmd.AddCommand(listOrganizationDeployTargetsCmd)
listCmd.AddCommand(ListOrganizationUsersCmd)
listCmd.Flags().BoolVarP(&listAllProjects, "all-projects", "", false, "All projects (if supported)")
listUsersCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list users in (if not specified, will default to all groups)")
listGroupProjectsCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list projects in")
listVariablesCmd.Flags().BoolP("reveal", "", false, "Reveal the variable values")
listOrganizationProjectsCmd.Flags().Uint("id", 0, "ID of the organization to list associated projects for")
ListOrganizationUsersCmd.Flags().String("organization", "", "Name of the organization to list associated users for")
listOrganizationGroupsCmd.Flags().Uint("id", 0, "ID of the organization to list associated groups for")
listDeployTargetsByOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated deploy targets for")
listOrganizationProjectsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated projects for")
ListOrganizationUsersCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated users for")
listOrganizationGroupsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated groups for")
listOrganizationDeployTargetsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated deploy targets for")
}
25 changes: 12 additions & 13 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
)

// TODO
var addOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Expand Down Expand Up @@ -105,12 +104,12 @@ var deleteOrganizationCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
organizationId, err := cmd.Flags().GetUint("id")
organizationName, err := cmd.Flags().GetString("organization")
if err != nil {
return err
}
if organizationId == 0 {
fmt.Println("Missing arguments: Organization ID is not defined")
if organizationName == "" {
fmt.Println("Missing arguments: Organization is not defined")
cmd.Help()
os.Exit(1)
}
Expand All @@ -123,10 +122,10 @@ var deleteOrganizationCmd = &cobra.Command{
&token,
debug)

organization, err := l.GetOrganizationByID(context.TODO(), organizationId, lc)
organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)
if yesNo(fmt.Sprintf("You are attempting to delete organization '%s', are you sure?", organization.Name)) {
_, err := l.DeleteOrganization(context.TODO(), organizationId, lc)
_, err := l.DeleteOrganization(context.TODO(), organization.ID, lc)
handleError(err)
resultData := output.Result{
Result: organization.Name,
Expand All @@ -137,7 +136,6 @@ var deleteOrganizationCmd = &cobra.Command{
},
}

// TODO - update once the API is updated
var updateOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Expand All @@ -150,7 +148,7 @@ var updateOrganizationCmd = &cobra.Command{
if err != nil {
return err
}
organizationId, err := cmd.Flags().GetUint("id")
organizationName, err := cmd.Flags().GetString("organization")
if err != nil {
return err
}
Expand Down Expand Up @@ -183,8 +181,8 @@ var updateOrganizationCmd = &cobra.Command{
return err
}

if organizationId == 0 {
fmt.Println("Missing arguments: Organization ID is not defined")
if organizationName == "" {
fmt.Println("Missing arguments: Organization is not defined")
cmd.Help()
os.Exit(1)
}
Expand All @@ -197,6 +195,7 @@ var updateOrganizationCmd = &cobra.Command{
&token,
debug)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
organizationInput := s.UpdateOrganizationPatchInput{
Description: nullStrCheck(organizationDescription),
FriendlyName: nullStrCheck(organizationFriendlyName),
Expand All @@ -206,7 +205,7 @@ var updateOrganizationCmd = &cobra.Command{
QuotaEnvironment: nullUintCheck(organizationQuotaEnvironment),
QuotaRoute: nullUintCheck(organizationQuotaRoute),
}
result, err := l.UpdateOrganization(context.TODO(), organizationId, organizationInput, lc)
result, err := l.UpdateOrganization(context.TODO(), organization.ID, organizationInput, lc)
handleError(err)

resultData := output.Result{
Expand All @@ -230,7 +229,7 @@ func init() {
addOrganizationCmd.Flags().Uint("quotaEnvironment", 0, "Environment quota for the organization")
addOrganizationCmd.Flags().Uint("quotaRoute", 0, "Route quota for the organization")

updateOrganizationCmd.Flags().Uint("id", 0, "ID of the organization to update")
updateOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization to update")
updateOrganizationCmd.Flags().String("friendlyName", "", "Friendly name of the organization")
updateOrganizationCmd.Flags().String("description", "", "Description of the organization")
updateOrganizationCmd.Flags().Uint("quotaProject", 0, "Project quota for the organization")
Expand All @@ -239,5 +238,5 @@ func init() {
updateOrganizationCmd.Flags().Uint("quotaEnvironment", 0, "Environment quota for the organization")
updateOrganizationCmd.Flags().Uint("quotaRoute", 0, "Route quota for the organization")

deleteOrganizationCmd.Flags().Uint("id", 0, "ID of the organization")
deleteOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization to delete")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.12-0.20231013065539-b9d9df834b25
github.com/uselagoon/machinery v0.0.12-0.20231015225416-9e8151292e0c
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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ github.com/uselagoon/machinery v0.0.12-0.20231011071234-6d83d527417a h1:dFLzyv5f
github.com/uselagoon/machinery v0.0.12-0.20231011071234-6d83d527417a/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.12-0.20231013065539-b9d9df834b25 h1:rwIaM/VlShiPdmIjly2uFOGqfZHFOsd/zieUoIsrcQA=
github.com/uselagoon/machinery v0.0.12-0.20231013065539-b9d9df834b25/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.12-0.20231015225416-9e8151292e0c h1:fguK6vwcaDQQkJyzAPGuy7VjzG1xZSNqYgekfIgepjc=
github.com/uselagoon/machinery v0.0.12-0.20231015225416-9e8151292e0c/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit d31a6fb

Please sign in to comment.