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

Method Execute

cf/commands/application/scale.go:79–159  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

77var bytesInAMegabyte int64 = 1024 * 1024
78
79func (cmd *Scale) Execute(c flags.FlagContext) error {
80 currentApp := cmd.appReq.GetApplication()
81 if !anyFlagsSet(c) {
82 cmd.ui.Say(T("Showing current scale of app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
83 map[string]interface{}{
84 "AppName": terminal.EntityNameColor(currentApp.Name),
85 "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
86 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
87 "CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
88 }))
89 cmd.ui.Ok()
90 cmd.ui.Say("")
91
92 cmd.ui.Say("%s %s", terminal.HeaderColor(T("memory:")), formatters.ByteSize(currentApp.Memory*bytesInAMegabyte))
93 cmd.ui.Say("%s %s", terminal.HeaderColor(T("disk:")), formatters.ByteSize(currentApp.DiskQuota*bytesInAMegabyte))
94 cmd.ui.Say("%s %d", terminal.HeaderColor(T("instances:")), currentApp.InstanceCount)
95
96 return nil
97 }
98
99 params := models.AppParams{}
100 shouldRestart := false
101
102 if c.String("m") != "" {
103 memory, err := formatters.ToMegabytes(c.String("m"))
104 if err != nil {
105 return errors.New(T("Invalid memory limit: {{.Memory}}\n{{.ErrorDescription}}",
106 map[string]interface{}{
107 "Memory": c.String("m"),
108 "ErrorDescription": err,
109 }))
110 }
111 params.Memory = &memory
112 shouldRestart = true
113 }
114
115 if c.String("k") != "" {
116 diskQuota, err := formatters.ToMegabytes(c.String("k"))
117 if err != nil {
118 return errors.New(T("Invalid disk quota: {{.DiskQuota}}\n{{.ErrorDescription}}",
119 map[string]interface{}{
120 "DiskQuota": c.String("k"),
121 "ErrorDescription": err,
122 }))
123 }
124 params.DiskQuota = &diskQuota
125 shouldRestart = true
126 }
127
128 if c.IsSet("i") {
129 instances := c.Int("i")
130 params.InstanceCount = &instances
131 }
132
133 if shouldRestart && !cmd.confirmRestart(c, currentApp.Name) {
134 return nil
135 }
136

Callers

nothing calls this directly

Calls 15

confirmRestartMethod · 0.95
EntityNameColorFunction · 0.92
HeaderColorFunction · 0.92
ByteSizeFunction · 0.92
ToMegabytesFunction · 0.92
anyFlagsSetFunction · 0.85
GetApplicationMethod · 0.65
SayMethod · 0.65
OrganizationFieldsMethod · 0.65
SpaceFieldsMethod · 0.65
UsernameMethod · 0.65
OkMethod · 0.65

Tested by

no test coverage detected