MCPcopy Index your code
hub / github.com/cli/cli / newListCmd

Function newListCmd

pkg/cmd/codespace/list.go:23–77  ·  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 err := cmdutil.MutuallyExclusive(
39 "using `--org` or `--user` with `--repo` is not allowed",
40 opts.repo != "",
41 opts.orgName != "" || opts.userName != "",
42 ); err != nil {
43 return err
44 }
45
46 if err := cmdutil.MutuallyExclusive(
47 "using `--web` with `--org` or `--user` is not supported, please use with `--repo` instead",
48 opts.useWeb,
49 opts.orgName != "" || opts.userName != "",
50 ); err != nil {
51 return err
52 }
53
54 if opts.limit < 1 {
55 return cmdutil.FlagErrorf("invalid limit: %v", opts.limit)
56 }
57 return nil
58 },
59 RunE: func(cmd *cobra.Command, args []string) error {
60 return app.List(cmd.Context(), opts, exporter)
61 },
62 }
63
64 listCmd.Flags().IntVarP(&opts.limit, "limit", "L", 30, "Maximum number of codespaces to list")
65 listCmd.Flags().StringVarP(&opts.repo, "repo", "R", "", "Repository name with owner: user/repo")
66 if err := addDeprecatedRepoShorthand(listCmd, &opts.repo); err != nil {
67 fmt.Fprintf(app.io.ErrOut, "%v\n", err)
68 }
69
70 listCmd.Flags().StringVarP(&opts.orgName, "org", "o", "", "The `login` handle of the organization to list codespaces for (admin-only)")
71 listCmd.Flags().StringVarP(&opts.userName, "user", "u", "", "The `username` to list codespaces for (used with --org)")
72 cmdutil.AddJSONFlags(listCmd, &exporter, api.ListCodespaceFields)
73
74 listCmd.Flags().BoolVarP(&opts.useWeb, "web", "w", false, "List codespaces in the web browser, cannot be used with --user or --org")
75
76 return listCmd
77}
78
79func (a *App) List(ctx context.Context, opts *listOptions, exporter cmdutil.Exporter) error {
80 if opts.useWeb && opts.repo == "" {

Callers 2

TestListCmdFlagErrorFunction · 0.85
NewCmdCodespaceFunction · 0.85

Calls 5

MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
AddJSONFlagsFunction · 0.92
ListMethod · 0.65

Tested by 1

TestListCmdFlagErrorFunction · 0.68