File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -169,12 +169,28 @@ func parseFileArg(fileArg string) (string, error) {
169169 if len (arr ) > 2 {
170170 return "" , fmt .Errorf ("invalid use of colon\n Use 'gh browse --help' for more information about browse\n " )
171171 }
172+
172173 if len (arr ) > 1 {
173- if ! isNumber (arr [1 ]) {
174- return "" , fmt .Errorf ("invalid line number after colon\n Use 'gh browse --help' for more information about browse\n " )
174+ out := arr [0 ] + "#L"
175+ lineRange := strings .Split (arr [1 ], "-" )
176+
177+ if len (lineRange ) > 0 {
178+ if ! isNumber (lineRange [0 ]) {
179+ return "" , fmt .Errorf ("invalid line number after colon\n Use 'gh browse --help' for more information about browse\n " )
180+ }
181+ out += lineRange [0 ]
182+ }
183+
184+ if len (lineRange ) > 1 {
185+ if ! isNumber (lineRange [1 ]) {
186+ return "" , fmt .Errorf ("invalid line range after colon\n Use 'gh browse --help' for more information about browse\n " )
187+ }
188+ out += "-L" + lineRange [1 ]
175189 }
176- return arr [0 ] + "#L" + arr [1 ], nil
190+
191+ return out , nil
177192 }
193+
178194 return arr [0 ], nil
179195}
180196
Original file line number Diff line number Diff line change @@ -215,6 +215,15 @@ func Test_runBrowse(t *testing.T) {
215215 defaultBranch : "trunk" ,
216216 expectedURL : "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32" ,
217217 },
218+ {
219+ name : "file with line range" ,
220+ opts : BrowseOptions {
221+ SelectorArg : "path/to/file.txt:32-40" ,
222+ },
223+ baseRepo : ghrepo .New ("ravocean" , "angur" ),
224+ defaultBranch : "trunk" ,
225+ expectedURL : "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32-L40" ,
226+ },
218227 {
219228 name : "file with invalid line number" ,
220229 opts : BrowseOptions {
@@ -223,6 +232,14 @@ func Test_runBrowse(t *testing.T) {
223232 baseRepo : ghrepo .New ("ttran112" , "ttrain211" ),
224233 wantsErr : true ,
225234 },
235+ {
236+ name : "file with invalid line range" ,
237+ opts : BrowseOptions {
238+ SelectorArg : "path/to/file.txt:32-abc" ,
239+ },
240+ baseRepo : ghrepo .New ("ttran112" , "ttrain211" ),
241+ wantsErr : true ,
242+ },
226243 {
227244 name : "branch with issue number" ,
228245 opts : BrowseOptions {
You can’t perform that action at this time.
0 commit comments