| 111 | } |
| 112 | |
| 113 | func viewRun(opts *ViewOptions) error { |
| 114 | repo, err := opts.BaseRepo() |
| 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | if err := shared.CheckHost(repo.RepoHost()); err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | c, err := opts.Client() |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | if err := shared.CheckIssue(c, repo, opts.IssueNumber); err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | artifact, err := c.Get(repo, opts.IssueNumber, opts.ArtifactNumber) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | if err := shared.CheckType(artifact.Artifact); err != nil { |
| 135 | return err |
| 136 | } |
| 137 | viewing, err := shared.FindVersion(artifact, opts.Version) |
| 138 | if err != nil { |
| 139 | return err |
| 140 | } |
| 141 | |
| 142 | if opts.WebMode { |
| 143 | return openInBrowser(opts, artifact.Artifact) |
| 144 | } |
| 145 | |
| 146 | if opts.Exporter != nil { |
| 147 | return opts.Exporter.Write(opts.IO, artifact) |
| 148 | } |
| 149 | |
| 150 | if !opts.IO.IsStdoutTTY() { |
| 151 | printRawArtifact(opts.IO.Out, artifact, viewing) |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | opts.IO.DetectTerminalTheme() |
| 156 | if err := opts.IO.StartPager(); err != nil { |
| 157 | fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err) |
| 158 | } |
| 159 | defer opts.IO.StopPager() |
| 160 | |
| 161 | return printHumanArtifact(opts, repo, artifact, viewing) |
| 162 | } |
| 163 | |
| 164 | // openInBrowser opens a document's page on GitHub, or a link's URL. The page |
| 165 | // comes from the API, so the message shows it like gh issue view --web does. |