MCPcopy Create free account
hub / github.com/cli/cli / viewRun

Function viewRun

pkg/cmd/repo/gitignore/view/view.go:67–100  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

65}
66
67func 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
102func renderGitIgnore(licenseTemplate *api.GitIgnore, opts *ViewOptions) error {
103 // I wanted to render this in a markdown code block and benefit

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 8

RepoGitIgnoreTemplateFunction · 0.92
renderGitIgnoreFunction · 0.85
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestViewRunFunction · 0.56