MCPcopy
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

pkg/cmd/project/view/view.go:31–82  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config viewConfig) error)

Source from the content-addressed store, hash-verified

29}
30
31func NewCmdView(f *cmdutil.Factory, runF func(config viewConfig) error) *cobra.Command {
32 opts := viewOpts{}
33 viewCmd := &cobra.Command{
34 Short: "View a project",
35 Use: "view [<number>]",
36 Example: heredoc.Doc(`
37 # View the current user's project "1"
38 $ gh project view 1
39
40 # Open user monalisa's project "1" in the browser
41 $ gh project view 1 --owner monalisa --web
42 `),
43 Args: cobra.MaximumNArgs(1),
44 RunE: func(cmd *cobra.Command, args []string) error {
45 client, err := client.New(f)
46 if err != nil {
47 return err
48 }
49
50 URLOpener := func(url string) error {
51 return f.Browser.Browse(url)
52 }
53
54 if len(args) == 1 {
55 num, err := strconv.ParseInt(args[0], 10, 32)
56 if err != nil {
57 return cmdutil.FlagErrorf("invalid number: %v", args[0])
58 }
59 opts.number = int32(num)
60 }
61
62 config := viewConfig{
63 client: client,
64 opts: opts,
65 io: f.IOStreams,
66 URLOpener: URLOpener,
67 }
68
69 // allow testing of the command without actually running it
70 if runF != nil {
71 return runF(config)
72 }
73 return runView(config)
74 },
75 }
76
77 viewCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.")
78 viewCmd.Flags().BoolVarP(&opts.web, "web", "w", false, "Open a project in the browser")
79 cmdutil.AddFormatFlags(viewCmd, &opts.exporter)
80
81 return viewCmd
82}
83
84func runView(config viewConfig) error {
85 canPrompt := config.io.CanPrompt()

Callers 1

TestNewCmdviewFunction · 0.70

Calls 5

NewFunction · 0.92
FlagErrorfFunction · 0.92
AddFormatFlagsFunction · 0.92
runViewFunction · 0.70
BrowseMethod · 0.65

Tested by 1

TestNewCmdviewFunction · 0.56