| 69 | } |
| 70 | |
| 71 | func 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 | } |