github.com/Liam-Williams/i18n4go@v0.2.7-0.20201028180611-670cbaceaa6b/test_fixtures/extract_strings/d_option/input_files/quota/delete_quota.go (about) 1 package quota 2 3 import () 4 5 type DeleteQuota struct { 6 ui terminal.UI 7 config configuration.Reader 8 quotaRepo api.QuotaRepository 9 orgReq requirements.OrganizationRequirement 10 } 11 12 func NewDeleteQuota(ui terminal.UI, config configuration.Reader, quotaRepo api.QuotaRepository) (cmd *DeleteQuota) { 13 cmd = new(DeleteQuota) 14 cmd.ui = ui 15 cmd.config = config 16 cmd.quotaRepo = quotaRepo 17 return 18 } 19 20 func (command *DeleteQuota) Metadata() command_metadata.CommandMetadata { 21 return command_metadata.CommandMetadata{ 22 Name: "delete-quota", 23 Description: "Delete a quota", 24 Usage: "CF_NAME delete-quota QUOTA [-f]", 25 Flags: []cli.Flag{ 26 cli.BoolFlag{Name: "f", Usage: "Force deletion without confirmation"}, 27 }, 28 } 29 } 30 31 func (cmd *DeleteQuota) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) { 32 if len(c.Args()) != 1 { 33 err = errors.New("Incorrect Usage") 34 cmd.ui.FailWithUsage(c, "delete-quota") 35 return 36 } 37 38 reqs = []requirements.Requirement{ 39 requirementsFactory.NewLoginRequirement(), 40 } 41 return 42 } 43 44 func (cmd *DeleteQuota) Run(c *cli.Context) { 45 quotaName := c.Args()[0] 46 47 if !c.Bool("f") { 48 response := cmd.ui.ConfirmDelete("quota", quotaName) 49 if !response { 50 return 51 } 52 } 53 54 cmd.ui.Say("Deleting quota %s as %s...", 55 terminal.EntityNameColor(quotaName), 56 terminal.EntityNameColor(cmd.config.Username()), 57 ) 58 59 quota, apiErr := cmd.quotaRepo.FindByName(quotaName) 60 61 switch (apiErr).(type) { 62 case nil: // no error 63 case *errors.ModelNotFoundError: 64 cmd.ui.Ok() 65 cmd.ui.Warn("Quota %s does not exist", quotaName) 66 return 67 default: 68 cmd.ui.Failed(apiErr.Error()) 69 } 70 71 apiErr = cmd.quotaRepo.Delete(quota.Guid) 72 if apiErr != nil { 73 cmd.ui.Failed(apiErr.Error()) 74 } 75 76 cmd.ui.Ok() 77 }