| 22 | } |
| 23 | |
| 24 | func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { |
| 25 | opts := &ViewOptions{ |
| 26 | IO: f.IOStreams, |
| 27 | HTTPClient: f.HttpClient, |
| 28 | Config: f.Config, |
| 29 | Template: "", |
| 30 | } |
| 31 | |
| 32 | cmd := &cobra.Command{ |
| 33 | Use: "view <template>", |
| 34 | Short: "View an available repository gitignore template", |
| 35 | Long: heredoc.Docf(` |
| 36 | View an available repository %[1]s.gitignore%[1]s template. |
| 37 | |
| 38 | %[1]s<template>%[1]s is a case-sensitive %[1]s.gitignore%[1]s template name. |
| 39 | |
| 40 | For a list of available templates, run %[1]sgh repo gitignore list%[1]s. |
| 41 | `, "`"), |
| 42 | Example: heredoc.Doc(` |
| 43 | # View the Go gitignore template |
| 44 | $ gh repo gitignore view Go |
| 45 | |
| 46 | # View the Python gitignore template |
| 47 | $ gh repo gitignore view Python |
| 48 | |
| 49 | # Create a new .gitignore file using the Go template |
| 50 | $ gh repo gitignore view Go > .gitignore |
| 51 | |
| 52 | # Create a new .gitignore file using the Python template |
| 53 | $ gh repo gitignore view Python > .gitignore |
| 54 | `), |
| 55 | Args: cobra.ExactArgs(1), |
| 56 | RunE: func(cmd *cobra.Command, args []string) error { |
| 57 | opts.Template = args[0] |
| 58 | if runF != nil { |
| 59 | return runF(opts) |
| 60 | } |
| 61 | return viewRun(opts) |
| 62 | }, |
| 63 | } |
| 64 | return cmd |
| 65 | } |
| 66 | |
| 67 | func viewRun(opts *ViewOptions) error { |
| 68 | if opts.Template == "" { |