MCPcopy
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/ruleset/list/list.go:95–176  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

93}
94
95func listRun(opts *ListOptions) error {
96 httpClient, err := opts.HttpClient()
97 if err != nil {
98 return err
99 }
100
101 var repoI ghrepo.Interface
102
103 // only one of the repo or org context is necessary
104 if opts.Organization == "" {
105 var repoErr error
106 repoI, repoErr = opts.BaseRepo()
107 if repoErr != nil {
108 return repoErr
109 }
110 }
111
112 hostname, _ := ghauth.DefaultHost()
113
114 if opts.WebMode {
115 var rulesetURL string
116 if opts.Organization != "" {
117 rulesetURL = fmt.Sprintf("%sorganizations/%s/settings/rules", ghinstance.HostPrefix(hostname), opts.Organization)
118 } else {
119 rulesetURL = ghrepo.GenerateRepoURL(repoI, "rules")
120 }
121
122 if opts.IO.IsStdoutTTY() {
123 fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", text.DisplayURL(rulesetURL))
124 }
125
126 return opts.Browser.Browse(rulesetURL)
127 }
128
129 var result *shared.RulesetList
130
131 if opts.Organization != "" {
132 result, err = shared.ListOrgRulesets(httpClient, opts.Organization, opts.Limit, hostname, opts.IncludeParents)
133 } else {
134 result, err = shared.ListRepoRulesets(httpClient, repoI, opts.Limit, opts.IncludeParents)
135 }
136
137 if err != nil {
138 return err
139 }
140
141 if result.TotalCount == 0 {
142 return shared.NoRulesetsFoundError(opts.Organization, repoI, opts.IncludeParents)
143 }
144
145 opts.IO.DetectTerminalTheme()
146 if err := opts.IO.StartPager(); err == nil {
147 defer opts.IO.StopPager()
148 } else {
149 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)
150 }
151
152 cs := opts.IO.ColorScheme()

Callers 2

Test_listRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

HostPrefixFunction · 0.92
GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
ListOrgRulesetsFunction · 0.92
ListRepoRulesetsFunction · 0.92
NoRulesetsFoundErrorFunction · 0.92
EntityNameFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
RulesetSourceFunction · 0.92
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80

Tested by 1

Test_listRunFunction · 0.56