| 65 | } |
| 66 | |
| 67 | func viewRun(opts *ViewOptions) error { |
| 68 | if opts.Template == "" { |
| 69 | return errors.New("no template provided") |
| 70 | } |
| 71 | |
| 72 | client, err := opts.HTTPClient() |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | cfg, err := opts.Config() |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | if err := opts.IO.StartPager(); err != nil { |
| 83 | fmt.Fprintf(opts.IO.ErrOut, "starting pager failed: %v\n", err) |
| 84 | } |
| 85 | defer opts.IO.StopPager() |
| 86 | |
| 87 | hostname, _ := cfg.Authentication().DefaultHost() |
| 88 | gitIgnore, err := api.RepoGitIgnoreTemplate(client, hostname, opts.Template) |
| 89 | if err != nil { |
| 90 | var httpErr api.HTTPError |
| 91 | if errors.As(err, &httpErr) { |
| 92 | if httpErr.StatusCode == 404 { |
| 93 | return fmt.Errorf("'%s' is not a valid gitignore template. Run `gh repo gitignore list` for options", opts.Template) |
| 94 | } |
| 95 | } |
| 96 | return err |
| 97 | } |
| 98 | |
| 99 | return renderGitIgnore(gitIgnore, opts) |
| 100 | } |
| 101 | |
| 102 | func renderGitIgnore(licenseTemplate *api.GitIgnore, opts *ViewOptions) error { |
| 103 | // I wanted to render this in a markdown code block and benefit |