MCPcopy
hub / github.com/cli/cli / NewCmdBrowse

Function NewCmdBrowse

pkg/cmd/browse/browse.go:52–185  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*BrowseOptions) error)

Source from the content-addressed store, hash-verified

50}
51
52func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Command {
53 opts := &BrowseOptions{
54 Browser: f.Browser,
55 HttpClient: f.HttpClient,
56 IO: f.IOStreams,
57 PathFromRepoRoot: func() string {
58 return f.GitClient.PathFromRoot(context.Background())
59 },
60 GitClient: &localGitClient{client: f.GitClient},
61 }
62
63 cmd := &cobra.Command{
64 Short: "Open repositories, issues, pull requests, and more in the browser",
65 Long: heredoc.Doc(`
66 Transition from the terminal to the web browser to view and interact with:
67
68 - Issues
69 - Pull requests
70 - Repository content
71 - Repository home page
72 - Repository settings
73 `),
74 Use: "browse [<number> | <path> | <commit-sha>]",
75 Args: cobra.MaximumNArgs(1),
76 Example: heredoc.Doc(`
77 # Open the home page of the current repository
78 $ gh browse
79
80 # Open the script directory of the current repository
81 $ gh browse script/
82
83 # Open issue or pull request 217
84 $ gh browse 217
85
86 # Open commit page
87 $ gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
88
89 # Open repository settings
90 $ gh browse --settings
91
92 # Open main.go at line 312
93 $ gh browse main.go:312
94
95 # Open blame view for main.go at line 312
96 $ gh browse main.go:312 --blame
97
98 # Open main.go with the repository at head of bug-fix branch
99 $ gh browse main.go --branch bug-fix
100
101 # Open main.go with the repository at commit 775007cd
102 $ gh browse main.go --commit=77507cd94ccafcf568f8560cfecde965fcfa63
103 `),
104 Annotations: map[string]string{
105 "help:arguments": heredoc.Doc(`
106 A browser location can be specified using arguments in the following format:
107 - by number for issue or pull request, e.g. "123"; or
108 - by path for opening folders and files, e.g. "cmd/gh/main.go"; or
109 - by commit SHA

Callers 1

TestNewCmdBrowseFunction · 0.85

Calls 8

MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
EnableRepoOverrideFunction · 0.92
isNumberFunction · 0.85
isCommitFunction · 0.85
runBrowseFunction · 0.85
PathFromRootMethod · 0.80

Tested by 1

TestNewCmdBrowseFunction · 0.68