@@ -55,11 +55,10 @@ func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
5555 }
5656
5757 cmd := & cobra.Command {
58- Long : "Work with GitHub in the browser" , // displays when you are on the help page of this command
59- Short : "Open GitHub in the browser" , // displays in the gh root help
60- Use : "browse" , // necessary!!! This is the cmd that gets passed on the prompt
61- Args : cobra .RangeArgs (0 , 2 ), // make sure only one arg at most is passed
62-
58+ Long : "Work with GitHub in the browser" , // displays when you are on the help page of this command
59+ Short : "Open GitHub in the browser" , // displays in the gh root help
60+ Use : "browse {<number> | <file> | <branch>}" , // necessary!!! This is the cmd that gets passed on the prompt
61+ Args : cobra .RangeArgs (0 , 2 ), // make sure only one arg at most is passed
6362 Example : heredoc .Doc (`
6463 $ gh browse
6564 #=> Opens repository in browser
@@ -73,7 +72,6 @@ func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
7372 $ gh browse src/fileName:312 --branch main
7473 #=> Opens src/fileName at line 312 in main branch
7574 ` ),
76-
7775 Annotations : map [string ]string {
7876 "IsCore" : "true" ,
7977 "help:arguments" : heredoc .Doc (`
@@ -82,7 +80,6 @@ func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
8280 - by file or branch name, e.g. "main.java" or "trunk".
8381 ` ),
8482 },
85-
8683 Run : func (cmd * cobra.Command , args []string ) {
8784
8885 if len (args ) > 1 {
@@ -104,25 +101,25 @@ func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
104101 return cmd
105102}
106103
107- func openInBrowser (cmd * cobra.Command , opts * BrowseOptions ) {
104+ func openInBrowser (cmd * cobra.Command , opts * BrowseOptions ) ( exitCode , string ) {
108105
109106 baseRepo , err := opts .BaseRepo ()
110107 httpClient , _ := opts .HttpClient ()
111108 apiClient := api .NewClientFromHTTP (httpClient )
112109 branchName , err := api .RepoDefaultBranch (apiClient , baseRepo )
113- response := exitSuccess
114110
115111 if ! inRepo (err ) { // must be in a repo to execute
116112 printExit (exitNotInRepo , cmd , opts , "" )
117- return
113+ return exitNotInRepo , ""
118114 }
119115
120116 if getFlagAmount (cmd ) > 1 { // command can't have more than one flag
121117 printExit (exitTooManyFlags , cmd , opts , "" )
122- return
118+ return exitTooManyFlags , ""
123119 }
124120
125121 repoUrl := ghrepo .GenerateRepoURL (baseRepo , "" )
122+ response := exitSuccess
126123
127124 if ! hasArg (opts ) && hasFlag (cmd ) {
128125 response , repoUrl = addFlag (opts , repoUrl )
@@ -137,7 +134,7 @@ func openInBrowser(cmd *cobra.Command, opts *BrowseOptions) {
137134 }
138135
139136 printExit (response , cmd , opts , repoUrl ) // print success
140-
137+ return response , repoUrl
141138}
142139
143140func addCombined (opts * BrowseOptions , url string , branchName string ) (exitCode , string ) {
0 commit comments