| 26 | } |
| 27 | |
| 28 | func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Command { |
| 29 | opts := &viewOptions{ |
| 30 | Browser: f.Browser, |
| 31 | IO: f.IOStreams, |
| 32 | } |
| 33 | |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "view <id>", |
| 36 | Short: "View an autolink reference", |
| 37 | Long: "View an autolink reference for a repository.", |
| 38 | Args: cobra.ExactArgs(1), |
| 39 | RunE: func(cmd *cobra.Command, args []string) error { |
| 40 | httpClient, err := f.HttpClient() |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | opts.BaseRepo = f.BaseRepo |
| 46 | opts.ID = args[0] |
| 47 | opts.AutolinkClient = &AutolinkViewer{HTTPClient: httpClient} |
| 48 | |
| 49 | if runF != nil { |
| 50 | return runF(opts) |
| 51 | } |
| 52 | |
| 53 | return viewRun(opts) |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.AutolinkFields) |
| 58 | |
| 59 | return cmd |
| 60 | } |
| 61 | |
| 62 | func viewRun(opts *viewOptions) error { |
| 63 | repo, err := opts.BaseRepo() |