MCPcopy Create free account
hub / github.com/cli/cli / newListCmd

Function newListCmd

pkg/cmd/codespace/list.go:23–83  ·  view source on GitHub ↗
(app *App)

Source from the content-addressed store, hash-verified

21}
22
23func newListCmd(app *App) *cobra.Command {
24 opts := &listOptions{}
25 var exporter cmdutil.Exporter
26
27 listCmd := &cobra.Command{
28 Use: "list",
29 Short: "List codespaces",
30 Long: heredoc.Doc(`
31 List codespaces of the authenticated user.
32
33 Alternatively, organization administrators may list all codespaces billed to the organization.
34 `),
35 Aliases: []string{"ls"},
36 Args: noArgsConstraint,
37 PreRunE: func(cmd *cobra.Command, args []string) error {
38 if opts.repo != "" {
39 if err := validateNWO(opts.repo); err != nil {
40 return cmdutil.FlagErrorf("invalid value for --repo: %v", err)
41 }
42 }
43
44 if err := cmdutil.MutuallyExclusive(
45 "using `--org` or `--user` with `--repo` is not allowed",
46 opts.repo != "",
47 opts.orgName != "" || opts.userName != "",
48 ); err != nil {
49 return err
50 }
51
52 if err := cmdutil.MutuallyExclusive(
53 "using `--web` with `--org` or `--user` is not supported, please use with `--repo` instead",
54 opts.useWeb,
55 opts.orgName != "" || opts.userName != "",
56 ); err != nil {
57 return err
58 }
59
60 if opts.limit < 1 {
61 return cmdutil.FlagErrorf("invalid limit: %v", opts.limit)
62 }
63 return nil
64 },
65 RunE: func(cmd *cobra.Command, args []string) error {
66 return app.List(cmd.Context(), opts, exporter)
67 },
68 }
69
70 listCmd.Flags().IntVarP(&opts.limit, "limit", "L", 30, "Maximum number of codespaces to list")
71 listCmd.Flags().StringVarP(&opts.repo, "repo", "R", "", "Repository name with owner: user/repo")
72 if err := addDeprecatedRepoShorthand(listCmd, &opts.repo); err != nil {
73 fmt.Fprintf(app.io.ErrOut, "%v\n", err)
74 }
75
76 listCmd.Flags().StringVarP(&opts.orgName, "org", "o", "", "The `login` handle of the organization to list codespaces for (admin-only)")
77 listCmd.Flags().StringVarP(&opts.userName, "user", "u", "", "The `username` to list codespaces for (used with --org)")
78 cmdutil.AddJSONFlags(listCmd, &exporter, api.ListCodespaceFields)
79
80 listCmd.Flags().BoolVarP(&opts.useWeb, "web", "w", false, "List codespaces in the web browser, cannot be used with --user or --org")

Callers 2

TestListCmdFlagErrorFunction · 0.85
NewCmdCodespaceFunction · 0.85

Calls 6

FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
AddJSONFlagsFunction · 0.92
validateNWOFunction · 0.85
ListMethod · 0.65

Tested by 1

TestListCmdFlagErrorFunction · 0.68