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

Function NewCmdView

pkg/cmd/repo/license/view/view.go:28–73  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ViewOptions) error)

Source from the content-addressed store, hash-verified

26}
27
28func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
29 opts := &ViewOptions{
30 IO: f.IOStreams,
31 HTTPClient: f.HttpClient,
32 Config: f.Config,
33 Browser: f.Browser,
34 }
35
36 cmd := &cobra.Command{
37 Use: "view {<license-key> | <spdx-id>}",
38 Short: "View a specific repository license",
39 Long: heredoc.Docf(`
40 View a specific repository license by license key or SPDX ID.
41
42 Run %[1]sgh repo license list%[1]s to see available commonly used licenses. For even more licenses, visit <https://choosealicense.com/appendix>.
43 `, "`"),
44 Example: heredoc.Doc(`
45 # View the MIT license from SPDX ID
46 $ gh repo license view MIT
47
48 # View the MIT license from license key
49 $ gh repo license view mit
50
51 # View the GNU AGPL-3.0 license from SPDX ID
52 $ gh repo license view AGPL-3.0
53
54 # View the GNU AGPL-3.0 license from license key
55 $ gh repo license view agpl-3.0
56
57 # Create a LICENSE.md with the MIT license
58 $ gh repo license view MIT > LICENSE.md
59 `),
60 Args: cobra.ExactArgs(1),
61 RunE: func(cmd *cobra.Command, args []string) error {
62 opts.License = args[0]
63 if runF != nil {
64 return runF(opts)
65 }
66 return viewRun(opts)
67 },
68 }
69
70 cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open https://choosealicense.com/ in the browser")
71
72 return cmd
73}
74
75func viewRun(opts *ViewOptions) error {
76 if opts.License == "" {

Callers 1

TestNewCmdViewFunction · 0.70

Calls 1

viewRunFunction · 0.70

Tested by 1

TestNewCmdViewFunction · 0.56