| 34 | } |
| 35 | |
| 36 | func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { |
| 37 | opts := ViewOptions{ |
| 38 | IO: f.IOStreams, |
| 39 | HttpClient: f.HttpClient, |
| 40 | BaseRepo: f.BaseRepo, |
| 41 | Browser: f.Browser, |
| 42 | Config: f.Config, |
| 43 | } |
| 44 | |
| 45 | cmd := &cobra.Command{ |
| 46 | Use: "view [<repository>]", |
| 47 | Short: "View a repository", |
| 48 | Long: heredoc.Docf(` |
| 49 | Display the description and the README of a GitHub repository. |
| 50 | |
| 51 | With no argument, the repository for the current directory is displayed. |
| 52 | |
| 53 | With %[1]s--web%[1]s, open the repository in a web browser instead. |
| 54 | |
| 55 | With %[1]s--branch%[1]s, view a specific branch of the repository. |
| 56 | `, "`"), |
| 57 | Args: cobra.MaximumNArgs(1), |
| 58 | RunE: func(c *cobra.Command, args []string) error { |
| 59 | if len(args) > 0 { |
| 60 | opts.RepoArg = args[0] |
| 61 | } |
| 62 | if runF != nil { |
| 63 | return runF(&opts) |
| 64 | } |
| 65 | return viewRun(&opts) |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open a repository in the browser") |
| 70 | cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "View a specific branch of the repository") |
| 71 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.RepositoryFields) |
| 72 | |
| 73 | _ = cmdutil.RegisterBranchCompletionFlags(f.GitClient, cmd, "branch") |
| 74 | |
| 75 | return cmd |
| 76 | } |
| 77 | |
| 78 | var defaultFields = []string{"name", "owner", "description"} |
| 79 | |