@@ -107,12 +107,12 @@ func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Co
107107func runBrowse (opts * BrowseOptions ) error {
108108 baseRepo , err := opts .BaseRepo ()
109109 if err != nil {
110- return fmt .Errorf ("unable to determine base repository: %w\n Use 'gh browse --help' for more information about browse \ n " , err )
110+ return fmt .Errorf ("unable to determine base repository: %w\n " , err )
111111 }
112112
113113 httpClient , err := opts .HttpClient ()
114114 if err != nil {
115- return fmt .Errorf ("unable to create an http client: %w\n Use 'gh browse --help' for more information about browse \ n " , err )
115+ return fmt .Errorf ("unable to create an http client: %w\n " , err )
116116 }
117117 url := ghrepo .GenerateRepoURL (baseRepo , "" )
118118
@@ -133,7 +133,7 @@ func runBrowse(opts *BrowseOptions) error {
133133 if isNumber (opts .SelectorArg ) {
134134 url += "/issues/" + opts .SelectorArg
135135 } else {
136- arr , err := parseFileArg (opts .SelectorArg )
136+ fileArg , err := parseFileArg (opts .SelectorArg )
137137 if err != nil {
138138 return err
139139 }
@@ -147,33 +147,28 @@ func runBrowse(opts *BrowseOptions) error {
147147 }
148148 url += "/tree/" + branchName + "/"
149149 }
150- if opts .SelectorArg != "" {
151- if len (arr ) > 1 {
152- url += arr [0 ] + "#L" + arr [1 ]
153- } else {
154- url += arr [0 ]
155- }
156- }
150+ url += fileArg
157151 }
158152 }
159153
160- err = opts .Browser .Browse (url )
161- if opts .IO .IsStdoutTTY () && err == nil {
154+ if opts .IO .IsStdoutTTY () {
162155 fmt .Fprintf (opts .IO .Out , "now opening %s in browser\n " , url )
163156 }
164-
165- return err
157+ return opts .Browser .Browse (url )
166158}
167159
168- func parseFileArg (fileArg string ) ([] string , error ) {
160+ func parseFileArg (fileArg string ) (string , error ) {
169161 arr := strings .Split (fileArg , ":" )
170162 if len (arr ) > 2 {
171- return arr , fmt .Errorf ("invalid use of colon\n Use 'gh browse --help' for more information about browse\n " )
163+ return "" , fmt .Errorf ("invalid use of colon\n Use 'gh browse --help' for more information about browse\n " )
172164 }
173- if len (arr ) > 1 && ! isNumber (arr [1 ]) {
174- return arr , fmt .Errorf ("invalid line number after colon\n Use 'gh browse --help' for more information about browse\n " )
165+ if len (arr ) > 1 {
166+ if ! isNumber (arr [1 ]) {
167+ return "" , fmt .Errorf ("invalid line number after colon\n Use 'gh browse --help' for more information about browse\n " )
168+ }
169+ return arr [0 ] + "#L" + arr [1 ], nil
175170 }
176- return arr , nil
171+ return arr [ 0 ] , nil
177172}
178173
179174func isNumber (arg string ) bool {
0 commit comments