TODO this command has no tests and doesn't follow the same patterns as our newer commands
(f factory.Factory)
| 17 | |
| 18 | // TODO this command has no tests and doesn't follow the same patterns as our newer commands |
| 19 | func NewCmdDelete(f factory.Factory) *cobra.Command { |
| 20 | var alreadyConfirmed bool |
| 21 | cmd := &cobra.Command{ |
| 22 | Use: "delete {<name> | <id>}", |
| 23 | Short: "Delete a space", |
| 24 | Long: "Delete a space in Octopus Deploy", |
| 25 | Aliases: []string{"del", "rm", "remove"}, |
| 26 | Example: heredoc.Docf(` |
| 27 | %[1]s space delete |
| 28 | %[1]s space rm |
| 29 | `, constants.ExecutableName), |
| 30 | RunE: func(cmd *cobra.Command, args []string) error { |
| 31 | if len(args) == 0 { |
| 32 | return deleteRun(f, cmd) |
| 33 | } |
| 34 | |
| 35 | itemIDOrName := args[0] |
| 36 | |
| 37 | octopus, err := f.GetSystemClient(apiclient.NewRequester(cmd)) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | // TODO slugs |
| 42 | itemToDelete, err := octopus.Spaces.GetByIDOrName(itemIDOrName) |
| 43 | if err != nil { // could be services.itemNotFound if they typed it wrong. |
| 44 | if err == services.ErrItemNotFound { |
| 45 | return fmt.Errorf("cannot find a space with name or ID of '%s'", itemIDOrName) |
| 46 | } |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | if alreadyConfirmed { |
| 51 | return stopQueueAndDelete(octopus, itemToDelete) |
| 52 | } else { |
| 53 | // TODO handle NO_PROMPT or CI mode. Should we require everyone to explicitly --confirm in CI mode or should we just go delete it? |
| 54 | // feels like being explicit would be better |
| 55 | return question.DeleteWithConfirmation(f.Ask, "space", itemToDelete.Name, itemToDelete.ID, func() error { |
| 56 | return stopQueueAndDelete(octopus, itemToDelete) |
| 57 | }) |
| 58 | } |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | question.RegisterConfirmDeletionFlag(cmd, &alreadyConfirmed, "space") |
| 63 | |
| 64 | return cmd |
| 65 | } |
| 66 | |
| 67 | func deleteRun(f factory.Factory, cmd *cobra.Command) error { |
| 68 | octopus, err := f.GetSystemClient(apiclient.NewRequester(cmd)) |
nothing calls this directly
no test coverage detected