github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/create_org_command.go (about) 1 package v7 2 3 import ( 4 "github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccerror" 5 "github.com/LukasHeimann/cloudfoundrycli/v8/command/flag" 6 ) 7 8 type CreateOrgCommand struct { 9 BaseCommand 10 11 RequiredArgs flag.Organization `positional-args:"yes"` 12 Quota string `short:"q" long:"quota" description:"Quota to assign to the newly created org"` 13 usage interface{} `usage:"CF_NAME create-org ORG [-q ORG_QUOTA]"` 14 relatedCommands interface{} `related_commands:"create-space, orgs, org-quotas, set-org-role"` 15 } 16 17 func (cmd CreateOrgCommand) Execute(args []string) error { 18 err := cmd.SharedActor.CheckTarget(false, false) 19 if err != nil { 20 return err 21 } 22 23 user, err := cmd.Actor.GetCurrentUser() 24 if err != nil { 25 return err 26 } 27 28 orgName := cmd.RequiredArgs.Organization 29 30 cmd.UI.DisplayTextWithFlavor("Creating org {{.Organization}} as {{.User}}...", 31 map[string]interface{}{ 32 "User": user.Name, 33 "Organization": orgName, 34 }) 35 36 org, warnings, err := cmd.Actor.CreateOrganization(orgName) 37 38 cmd.UI.DisplayWarnings(warnings) 39 if err != nil { 40 if _, ok := err.(ccerror.OrganizationNameTakenError); ok { 41 cmd.UI.DisplayText(err.Error()) 42 cmd.UI.DisplayOK() 43 return nil 44 } 45 return err 46 } 47 cmd.UI.DisplayOK() 48 49 if cmd.Quota != "" { 50 cmd.UI.DisplayTextWithFlavor("Setting org quota {{.Quota}} to org {{.Organization}} as {{.User}}...", 51 map[string]interface{}{ 52 "Quota": cmd.Quota, 53 "Organization": orgName, 54 "User": user.Name, 55 }) 56 warnings, err = cmd.Actor.ApplyOrganizationQuotaByName(cmd.Quota, org.GUID) 57 cmd.UI.DisplayWarnings(warnings) 58 if err != nil { 59 return err 60 } 61 cmd.UI.DisplayOK() 62 } 63 64 cmd.UI.DisplayText(`TIP: Use 'cf target -o "{{.Organization}}"' to target new org`, 65 map[string]interface{}{ 66 "Organization": orgName, 67 }) 68 69 return nil 70 }