github.com/Liam-Williams/i18n4go@v0.2.7-0.20201028180611-670cbaceaa6b/test_fixtures/extract_strings/d_option/input_files/quota/update_quota.go (about) 1 package quota 2 3 import () 4 5 type updateQuota struct { 6 ui terminal.UI 7 config configuration.Reader 8 quotaRepo api.QuotaRepository 9 } 10 11 func NewUpdateQuota(ui terminal.UI, config configuration.Reader, quotaRepo api.QuotaRepository) *updateQuota { 12 return &updateQuota{ 13 ui: ui, 14 config: config, 15 quotaRepo: quotaRepo, 16 } 17 } 18 19 func (command *updateQuota) Metadata() command_metadata.CommandMetadata { 20 return command_metadata.CommandMetadata{ 21 Name: "update-quota", 22 Description: "Update an existing resource quota", 23 Usage: "CF_NAME update-quota QUOTA [-m MEMORY] [-n NEW_NAME] [-r ROUTES] [-s SERVICE_INSTANCES] [--allow-paid-service-plans | --disallow-paid-service-plans]", 24 Flags: []cli.Flag{ 25 flag_helpers.NewStringFlag("m", "Total amount of memory (e.g. 1024M, 1G, 10G)"), 26 flag_helpers.NewStringFlag("n", "New name"), 27 flag_helpers.NewIntFlag("r", "Total number of routes"), 28 flag_helpers.NewIntFlag("s", "Total number of service instances"), 29 cli.BoolFlag{Name: "allow-paid-service-plans", Usage: "Can provision instances of paid service plans"}, 30 cli.BoolFlag{Name: "disallow-paid-service-plans", Usage: "Cannot provision instances of paid service plans"}, 31 }, 32 } 33 } 34 35 func (cmd *updateQuota) GetRequirements(requirementsFactory requirements.Factory, context *cli.Context) ([]requirements.Requirement, error) { 36 if len(context.Args()) != 1 { 37 cmd.ui.FailWithUsage(context, "update-quota") 38 } 39 40 return []requirements.Requirement{ 41 requirementsFactory.NewLoginRequirement(), 42 }, nil 43 } 44 45 func (cmd *updateQuota) Run(c *cli.Context) { 46 oldQuotaName := c.Args()[0] 47 quota, err := cmd.quotaRepo.FindByName(oldQuotaName) 48 49 if err != nil { 50 cmd.ui.Failed(err.Error()) 51 } 52 53 allowPaidServices := c.Bool("allow-paid-service-plans") 54 disallowPaidServices := c.Bool("disallow-paid-service-plans") 55 if allowPaidServices && disallowPaidServices { 56 cmd.ui.Failed("Please choose either allow or disallow. Both flags are not permitted to be passed in the same command. ") 57 } 58 59 if allowPaidServices { 60 quota.NonBasicServicesAllowed = true 61 } 62 63 if disallowPaidServices { 64 quota.NonBasicServicesAllowed = false 65 } 66 67 if c.String("m") != "" { 68 memory, formatError := formatters.ToMegabytes(c.String("m")) 69 70 if formatError != nil { 71 cmd.ui.FailWithUsage(c, "update-quota") 72 } 73 74 quota.MemoryLimit = memory 75 } 76 77 if c.String("n") != "" { 78 quota.Name = c.String("n") 79 } 80 81 if c.IsSet("s") { 82 quota.ServicesLimit = c.Int("s") 83 } 84 85 if c.IsSet("r") { 86 quota.RoutesLimit = c.Int("r") 87 } 88 89 cmd.ui.Say("Updating quota %s as %s...", 90 terminal.EntityNameColor(oldQuotaName), 91 terminal.EntityNameColor(cmd.config.Username())) 92 93 err = cmd.quotaRepo.Update(quota) 94 if err != nil { 95 cmd.ui.Failed(err.Error()) 96 } 97 cmd.ui.Ok() 98 }