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

Method List

pkg/cmd/codespace/list.go:79–185  ·  view source on GitHub ↗
(ctx context.Context, opts *listOptions, exporter cmdutil.Exporter)

Source from the content-addressed store, hash-verified

77}
78
79func (a *App) List(ctx context.Context, opts *listOptions, exporter cmdutil.Exporter) error {
80 if opts.useWeb && opts.repo == "" {
81 return a.browser.Browse(fmt.Sprintf("%s/codespaces", a.apiClient.ServerURL()))
82 }
83
84 var codespaces []*api.Codespace
85 err := a.RunWithProgress("Fetching codespaces", func() (err error) {
86 codespaces, err = a.apiClient.ListCodespaces(ctx, api.ListCodespacesOptions{Limit: opts.limit, RepoName: opts.repo, OrgName: opts.orgName, UserName: opts.userName})
87 return
88 })
89 if err != nil {
90 return fmt.Errorf("error getting codespaces: %w", err)
91 }
92
93 hasNonProdVSCSTarget := false
94 for _, apiCodespace := range codespaces {
95 if apiCodespace.VSCSTarget != "" && apiCodespace.VSCSTarget != api.VSCSTargetProduction {
96 hasNonProdVSCSTarget = true
97 break
98 }
99 }
100
101 if err := a.io.StartPager(); err != nil {
102 a.errLogger.Printf("error starting pager: %v", err)
103 }
104 defer a.io.StopPager()
105
106 if exporter != nil {
107 return exporter.Write(a.io, codespaces)
108 }
109
110 if len(codespaces) == 0 {
111 return cmdutil.NewNoResultsError("no codespaces found")
112 }
113
114 if opts.useWeb && codespaces[0].Repository.ID > 0 {
115 return a.browser.Browse(fmt.Sprintf("%s/codespaces?repository_id=%d", a.apiClient.ServerURL(), codespaces[0].Repository.ID))
116 }
117
118 headers := []string{
119 "NAME",
120 "DISPLAY NAME",
121 }
122 if opts.orgName != "" {
123 headers = append(headers, "OWNER")
124 }
125 headers = append(headers,
126 "REPOSITORY",
127 "BRANCH",
128 "STATE",
129 "CREATED AT",
130 )
131 if hasNonProdVSCSTarget {
132 headers = append(headers, "VSCS TARGET")
133 }
134 tp := tableprinter.New(a.io, tableprinter.WithHeader(headers...))
135
136 cs := a.io.ColorScheme()

Callers 1

TestApp_ListFunction · 0.95

Calls 15

RunWithProgressMethod · 0.95
branchWithGitStatusMethod · 0.95
NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
formatNameForVSCSTargetFunction · 0.85
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ColorSchemeMethod · 0.80
AddTimeFieldMethod · 0.80
BrowseMethod · 0.65
ServerURLMethod · 0.65

Tested by 1

TestApp_ListFunction · 0.76