Skip to content

Commit

Permalink
Extends add & update cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Oct 3, 2023
1 parent fe9078e commit 4fac406
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 23 deletions.
16 changes: 1 addition & 15 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var updateEnvironmentCmd = &cobra.Command{
Route: nullStrCheck(route),
Routes: nullStrCheck(routes),
DeployTitle: nullStrCheck(deployTitle),
Openshift: nullIntCheck(openShift),
Openshift: nullUintCheck(openShift),
}
if environmentAutoIdleProvided {
environmentFlags.AutoIdle = &environmentAutoIdle
Expand Down Expand Up @@ -158,20 +158,6 @@ var updateEnvironmentCmd = &cobra.Command{
},
}

func nullStrCheck(s string) *string {
if s == "" {
return nil
}
return &s
}

func nullIntCheck(i uint) *uint {
if i == 0 {
return nil
}
return &i
}

func checkFlags(f *pflag.Flag) {
if f.Name == "auto-idle" {
environmentAutoIdleProvided = true
Expand Down
95 changes: 88 additions & 7 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ var addOrganizationCmd = &cobra.Command{
if err != nil {
return err
}
organizationFriendlyName, err := cmd.Flags().GetString("friendlyName")
if err != nil {
return err
}
organizationDescription, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
organizationQuotaProject, err := cmd.Flags().GetUint("quotaProject")
if err != nil {
return err
}
organizationQuotaGroup, err := cmd.Flags().GetUint("quotaGroup")
if err != nil {
return err
}
organizationQuotaNotification, err := cmd.Flags().GetUint("quotaNotification")
if err != nil {
return err
}
organizationQuotaEnvironment, err := cmd.Flags().GetUint("quotaEnvironment")
if err != nil {
return err
}
organizationQuotaRoute, err := cmd.Flags().GetUint("quotaRoute")
if err != nil {
return err
}

if organizationName == "" {
fmt.Println("Missing arguments: Organization name is not defined")
cmd.Help()
Expand All @@ -43,7 +72,14 @@ var addOrganizationCmd = &cobra.Command{
debug)

organizationInput := s.AddOrganizationInput{
Name: organizationName,
Name: organizationName,
FriendlyName: organizationFriendlyName,
Description: organizationDescription,
QuotaProject: organizationQuotaProject,
QuotaGroup: organizationQuotaGroup,
QuotaNotification: organizationQuotaNotification,
QuotaEnvironment: organizationQuotaEnvironment,
QuotaRoute: organizationQuotaRoute,
}
org := s.Organization{}
err = lc.AddOrganization(context.TODO(), &organizationInput, &org)
Expand Down Expand Up @@ -118,7 +154,31 @@ var updateOrganizationCmd = &cobra.Command{
if err != nil {
return err
}
description, err := cmd.Flags().GetString("description")
organizationFriendlyName, err := cmd.Flags().GetString("friendlyName")
if err != nil {
return err
}
organizationDescription, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
organizationQuotaProject, err := cmd.Flags().GetUint("quotaProject")
if err != nil {
return err
}
organizationQuotaGroup, err := cmd.Flags().GetUint("quotaGroup")
if err != nil {
return err
}
organizationQuotaNotification, err := cmd.Flags().GetUint("quotaNotification")
if err != nil {
return err
}
organizationQuotaEnvironment, err := cmd.Flags().GetUint("quotaEnvironment")
if err != nil {
return err
}
organizationQuotaRoute, err := cmd.Flags().GetUint("quotaRoute")
if err != nil {
return err
}
Expand All @@ -137,10 +197,16 @@ var updateOrganizationCmd = &cobra.Command{
&token,
debug)

organizationFlags := s.UpdateOrganizationPatchInput{
Description: description,
organizationInput := s.UpdateOrganizationPatchInput{
Description: nullStrCheck(organizationDescription),
FriendlyName: nullStrCheck(organizationFriendlyName),
QuotaProject: nullUintCheck(organizationQuotaProject),
QuotaGroup: nullUintCheck(organizationQuotaGroup),
QuotaNotification: nullUintCheck(organizationQuotaNotification),
QuotaEnvironment: nullUintCheck(organizationQuotaEnvironment),
QuotaRoute: nullUintCheck(organizationQuotaRoute),
}
result, err := l.UpdateOrganization(context.TODO(), organizationId, organizationFlags, lc)
result, err := l.UpdateOrganization(context.TODO(), organizationId, organizationInput, lc)
handleError(err)

resultData := output.Result{
Expand All @@ -155,8 +221,23 @@ var updateOrganizationCmd = &cobra.Command{
}

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")
addOrganizationCmd.Flags().String("friendlyName", "", "Friendly name of the organization")
addOrganizationCmd.Flags().String("description", "", "Description of the organization")
addOrganizationCmd.Flags().Uint("quotaProject", 0, "Project quota for the organization")
addOrganizationCmd.Flags().Uint("quotaGroup", 0, "Group quota for the organization")
addOrganizationCmd.Flags().Uint("quotaNotification", 0, "Notification quota for the organization")
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().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")
updateOrganizationCmd.Flags().Uint("quotaGroup", 0, "Group quota for the organization")
updateOrganizationCmd.Flags().Uint("quotaNotification", 0, "Notification quota for the organization")
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")
}
14 changes: 14 additions & 0 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ func fileExists(filename string) bool {
func stripNewLines(stripString string) string {
return strings.TrimSuffix(stripString, "\n")
}

func nullStrCheck(s string) *string {
if s == "" {
return nil
}
return &s
}

func nullUintCheck(i uint) *uint {
if i == 0 {
return nil
}
return &i
}
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.20230928085239-eaa5a60c02b6
github.com/uselagoon/machinery v0.0.12-0.20231003053009-de29ad78dc9a
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
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand Down Expand Up @@ -107,6 +109,10 @@ github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYv
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/uselagoon/machinery v0.0.11 h1:s6EhyU/pj1+C4FdS0EqmR6C0dLsoeCd9n+5xHL1YDag=
github.com/uselagoon/machinery v0.0.11/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12-0.20230928085239-eaa5a60c02b6 h1:Kitan9fWB7Q78ZFYMgiXBRdkwramMSToursudE2Uta8=
github.com/uselagoon/machinery v0.0.12-0.20230928085239-eaa5a60c02b6/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.12-0.20231003053009-de29ad78dc9a h1:B3pt6iYnNFCvQlIqsUvX5MdwGfN5iXeoyWTf6cerNj4=
github.com/uselagoon/machinery v0.0.12-0.20231003053009-de29ad78dc9a/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 4fac406

Please sign in to comment.