MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Execute

Method Execute

command/v7/create_route_command.go:44–104  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

42}
43
44func (cmd CreateRouteCommand) Execute(args []string) error {
45 err := cmd.SharedActor.CheckTarget(true, true)
46 if err != nil {
47 return err
48 }
49
50 user, err := cmd.Actor.GetCurrentUser()
51 if err != nil {
52 return err
53 }
54
55 domain := cmd.RequiredArgs.Domain
56 hostname := cmd.Hostname
57 pathName := cmd.Path.Path
58 port := cmd.Port
59 spaceName := cmd.Config.TargetedSpace().Name
60 orgName := cmd.Config.TargetedOrganization().Name
61 spaceGUID := cmd.Config.TargetedSpace().GUID
62 url := desiredURL(domain, hostname, pathName, port)
63
64 cmd.UI.DisplayTextWithFlavor("Creating route {{.URL}} for org {{.Organization}} / space {{.Space}} as {{.User}}...",
65 map[string]interface{}{
66 "URL": url,
67 "User": user.Name,
68 "Space": spaceName,
69 "Organization": orgName,
70 })
71
72 var routeOptions map[string]*string
73 if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
74 var wrongOptSpec *string
75 routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
76 if wrongOptSpec != nil {
77 return actionerror.RouteOptionError{
78 Name: *wrongOptSpec,
79 DomainName: domain,
80 Path: pathName,
81 Host: hostname,
82 }
83 }
84 }
85 route, warnings, err := cmd.Actor.CreateRoute(spaceGUID, domain, hostname, pathName, port, routeOptions)
86
87 cmd.UI.DisplayWarnings(warnings)
88 if err != nil {
89 if _, ok := err.(actionerror.RouteAlreadyExistsError); ok {
90 cmd.UI.DisplayWarning(err.Error())
91 cmd.UI.DisplayOK()
92 return nil
93 }
94 return err
95 }
96
97 cmd.UI.DisplayText("Route {{.URL}} has been created.",
98 map[string]interface{}{
99 "URL": route.URL,
100 })
101

Callers

nothing calls this directly

Calls 14

CreateRouteOptionsFunction · 0.92
desiredURLFunction · 0.85
CheckTargetMethod · 0.65
GetCurrentUserMethod · 0.65
TargetedSpaceMethod · 0.65
TargetedOrganizationMethod · 0.65
DisplayTextWithFlavorMethod · 0.65
CreateRouteMethod · 0.65
DisplayWarningsMethod · 0.65
DisplayWarningMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected