(app *App)
| 37 | } |
| 38 | |
| 39 | func newDeleteCmd(app *App) *cobra.Command { |
| 40 | opts := deleteOptions{ |
| 41 | isInteractive: hasTTY, |
| 42 | now: time.Now, |
| 43 | prompter: &surveyPrompter{}, |
| 44 | } |
| 45 | |
| 46 | var selector *CodespaceSelector |
| 47 | |
| 48 | deleteCmd := &cobra.Command{ |
| 49 | Use: "delete", |
| 50 | Short: "Delete codespaces", |
| 51 | Long: heredoc.Doc(` |
| 52 | Delete codespaces based on selection criteria. |
| 53 | |
| 54 | All codespaces for the authenticated user can be deleted, as well as codespaces for a |
| 55 | specific repository. Alternatively, only codespaces older than N days can be deleted. |
| 56 | |
| 57 | Organization administrators may delete any codespace billed to the organization. |
| 58 | `), |
| 59 | Args: noArgsConstraint, |
| 60 | RunE: func(cmd *cobra.Command, args []string) error { |
| 61 | // TODO: ideally we would use the selector directly, but the logic here is too intertwined with other flags to do so elegantly |
| 62 | // After the admin subcommand is added (see https://github.com/cli/cli/pull/6944#issuecomment-1419553639) we can revisit this. |
| 63 | opts.codespaceName = selector.codespaceName |
| 64 | opts.repoFilter = selector.repoName |
| 65 | opts.repoOwner = selector.repoOwner |
| 66 | |
| 67 | if opts.deleteAll && opts.repoFilter != "" { |
| 68 | return cmdutil.FlagErrorf("both `--all` and `--repo` is not supported") |
| 69 | } |
| 70 | |
| 71 | if opts.orgName != "" && opts.codespaceName != "" && opts.userName == "" { |
| 72 | return cmdutil.FlagErrorf("using `--org` with `--codespace` requires `--user`") |
| 73 | } |
| 74 | return app.Delete(cmd.Context(), opts) |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | selector = AddCodespaceSelector(deleteCmd, app.apiClient) |
| 79 | if err := addDeprecatedRepoShorthand(deleteCmd, &selector.repoName); err != nil { |
| 80 | fmt.Fprintf(app.io.ErrOut, "%v\n", err) |
| 81 | } |
| 82 | |
| 83 | deleteCmd.Flags().BoolVar(&opts.deleteAll, "all", false, "Delete all codespaces") |
| 84 | deleteCmd.Flags().BoolVarP(&opts.skipConfirm, "force", "f", false, "Skip confirmation for codespaces that contain unsaved changes") |
| 85 | deleteCmd.Flags().Uint16Var(&opts.keepDays, "days", 0, "Delete codespaces older than `N` days") |
| 86 | deleteCmd.Flags().StringVarP(&opts.orgName, "org", "o", "", "The `login` handle of the organization (admin-only)") |
| 87 | deleteCmd.Flags().StringVarP(&opts.userName, "user", "u", "", "The `username` to delete codespaces for (used with --org)") |
| 88 | |
| 89 | return deleteCmd |
| 90 | } |
| 91 | |
| 92 | func (a *App) Delete(ctx context.Context, opts deleteOptions) (err error) { |
| 93 | var codespaces []*api.Codespace |
no test coverage detected