| 30 | } |
| 31 | |
| 32 | func NewCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Command { |
| 33 | opts := &listOptions{ |
| 34 | Browser: f.Browser, |
| 35 | IO: f.IOStreams, |
| 36 | } |
| 37 | |
| 38 | cmd := &cobra.Command{ |
| 39 | Use: "list", |
| 40 | Short: "List autolink references for a GitHub repository", |
| 41 | Long: heredoc.Doc(` |
| 42 | Gets all autolink references that are configured for a repository. |
| 43 | |
| 44 | Information about autolinks is only available to repository administrators. |
| 45 | `), |
| 46 | Aliases: []string{"ls"}, |
| 47 | Args: cobra.NoArgs, |
| 48 | RunE: func(cmd *cobra.Command, args []string) error { |
| 49 | opts.BaseRepo = f.BaseRepo |
| 50 | |
| 51 | httpClient, err := f.HttpClient() |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | opts.AutolinkClient = &AutolinkLister{HTTPClient: httpClient} |
| 56 | |
| 57 | if runF != nil { |
| 58 | return runF(opts) |
| 59 | } |
| 60 | |
| 61 | return listRun(opts) |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "List autolink references in the web browser") |
| 66 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.AutolinkFields) |
| 67 | |
| 68 | return cmd |
| 69 | } |
| 70 | |
| 71 | func listRun(opts *listOptions) error { |
| 72 | repo, err := opts.BaseRepo() |