Merge pull request #4253 from despreston/4248-line-range
feat(4248): add support for line range w/ browse
This commit is contained in:
commit
abfe29617a
2 changed files with 36 additions and 3 deletions
|
|
@ -169,12 +169,28 @@ func parseFileArg(fileArg string) (string, error) {
|
|||
if len(arr) > 2 {
|
||||
return "", fmt.Errorf("invalid use of colon\nUse 'gh browse --help' for more information about browse\n")
|
||||
}
|
||||
|
||||
if len(arr) > 1 {
|
||||
if !isNumber(arr[1]) {
|
||||
return "", fmt.Errorf("invalid line number after colon\nUse 'gh browse --help' for more information about browse\n")
|
||||
out := arr[0] + "#L"
|
||||
lineRange := strings.Split(arr[1], "-")
|
||||
|
||||
if len(lineRange) > 0 {
|
||||
if !isNumber(lineRange[0]) {
|
||||
return "", fmt.Errorf("invalid line number after colon\nUse 'gh browse --help' for more information about browse\n")
|
||||
}
|
||||
out += lineRange[0]
|
||||
}
|
||||
return arr[0] + "#L" + arr[1], nil
|
||||
|
||||
if len(lineRange) > 1 {
|
||||
if !isNumber(lineRange[1]) {
|
||||
return "", fmt.Errorf("invalid line range after colon\nUse 'gh browse --help' for more information about browse\n")
|
||||
}
|
||||
out += "-L" + lineRange[1]
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -215,6 +215,15 @@ func Test_runBrowse(t *testing.T) {
|
|||
defaultBranch: "trunk",
|
||||
expectedURL: "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32",
|
||||
},
|
||||
{
|
||||
name: "file with line range",
|
||||
opts: BrowseOptions{
|
||||
SelectorArg: "path/to/file.txt:32-40",
|
||||
},
|
||||
baseRepo: ghrepo.New("ravocean", "angur"),
|
||||
defaultBranch: "trunk",
|
||||
expectedURL: "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32-L40",
|
||||
},
|
||||
{
|
||||
name: "file with invalid line number",
|
||||
opts: BrowseOptions{
|
||||
|
|
@ -223,6 +232,14 @@ func Test_runBrowse(t *testing.T) {
|
|||
baseRepo: ghrepo.New("ttran112", "ttrain211"),
|
||||
wantsErr: true,
|
||||
},
|
||||
{
|
||||
name: "file with invalid line range",
|
||||
opts: BrowseOptions{
|
||||
SelectorArg: "path/to/file.txt:32-abc",
|
||||
},
|
||||
baseRepo: ghrepo.New("ttran112", "ttrain211"),
|
||||
wantsErr: true,
|
||||
},
|
||||
{
|
||||
name: "branch with issue number",
|
||||
opts: BrowseOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue