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

Function listRun

pkg/cmd/repo/list/list.go:119–216  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

117var defaultFields = []string{"nameWithOwner", "description", "isPrivate", "isFork", "isArchived", "createdAt", "pushedAt"}
118
119func listRun(opts *ListOptions) error {
120 httpClient, err := opts.HttpClient()
121 if err != nil {
122 return err
123 }
124
125 cfg, err := opts.Config()
126 if err != nil {
127 return err
128 }
129
130 host, _ := cfg.Authentication().DefaultHost()
131
132 if opts.Detector == nil {
133 opts.Detector = fd.NewCachedDetector(httpClient, host, time.Hour*24)
134 }
135 features, err := opts.Detector.RepositoryFeatures()
136 if err != nil {
137 return err
138 }
139
140 fields := defaultFields
141 // TODO repoFeaturesCleanup
142 if features.VisibilityField {
143 fields = append(defaultFields, "visibility")
144 }
145
146 filter := FilterOptions{
147 Visibility: opts.Visibility,
148 Fork: opts.Fork,
149 Source: opts.Source,
150 Language: opts.Language,
151 Topic: opts.Topic,
152 Archived: opts.Archived,
153 NonArchived: opts.NonArchived,
154 Fields: fields,
155 }
156 if opts.Exporter != nil {
157 filter.Fields = opts.Exporter.Fields()
158 }
159
160 listResult, err := listRepos(httpClient, host, opts.Limit, opts.Owner, filter)
161 if err != nil {
162 return err
163 }
164
165 if opts.Owner != "" && listResult.Owner == "" && !listResult.FromSearch {
166 return fmt.Errorf("the owner handle %q was not recognized as either a GitHub user or an organization", opts.Owner)
167 }
168
169 if err := opts.IO.StartPager(); err != nil {
170 fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err)
171 }
172 defer opts.IO.StopPager()
173
174 if opts.Exporter != nil {
175 return opts.Exporter.Write(opts.IO, listResult.Repositories)
176 }

Callers 5

TestRepoList_nonttyFunction · 0.70
TestRepoList_ttyFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

NewFunction · 0.92
WithHeaderFunction · 0.92
listReposFunction · 0.85
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ColorSchemeMethod · 0.80
AddTimeFieldMethod · 0.80
IsStdoutTTYMethod · 0.80
repoInfoFunction · 0.70
listHeaderFunction · 0.70
ConfigMethod · 0.65

Tested by 4

TestRepoList_nonttyFunction · 0.56
TestRepoList_ttyFunction · 0.56