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

Function listRun

pkg/cmd/repo/autolink/list/list.go:71–126  ·  view source on GitHub ↗
(opts *listOptions)

Source from the content-addressed store, hash-verified

69}
70
71func listRun(opts *listOptions) error {
72 repo, err := opts.BaseRepo()
73 if err != nil {
74 return err
75 }
76
77 if opts.WebMode {
78 autolinksListURL := ghrepo.GenerateRepoURL(repo, "settings/key_links")
79
80 if opts.IO.IsStdoutTTY() {
81 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(autolinksListURL))
82 }
83
84 return opts.Browser.Browse(autolinksListURL)
85 }
86
87 autolinks, err := opts.AutolinkClient.List(repo)
88 if err != nil {
89 return err
90 }
91
92 cs := opts.IO.ColorScheme()
93
94 if len(autolinks) == 0 {
95 return cmdutil.NewNoResultsError(
96 fmt.Sprintf(
97 "no autolinks found in %s",
98 cs.Bold(ghrepo.FullName(repo))),
99 )
100 }
101
102 if opts.Exporter != nil {
103 return opts.Exporter.Write(opts.IO, autolinks)
104 }
105
106 if opts.IO.IsStdoutTTY() {
107 title := fmt.Sprintf(
108 "Showing %s in %s",
109 text.Pluralize(len(autolinks), "autolink reference"),
110 cs.Bold(ghrepo.FullName(repo)),
111 )
112 fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
113 }
114
115 tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "KEY PREFIX", "URL TEMPLATE", "ALPHANUMERIC"))
116
117 for _, autolink := range autolinks {
118 tp.AddField(cs.Cyanf("%d", autolink.ID))
119 tp.AddField(autolink.KeyPrefix)
120 tp.AddField(autolink.URLTemplate)
121 tp.AddField(strconv.FormatBool(autolink.IsAlphanumeric))
122 tp.EndRow()
123 }
124
125 return tp.Render()
126}

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
NewNoResultsErrorFunction · 0.92
FullNameFunction · 0.92
PluralizeFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
BoldMethod · 0.80
CyanfMethod · 0.80
BaseRepoMethod · 0.65

Tested by 1

TestListRunFunction · 0.56