Handle bogus pager gracefully

This commit is contained in:
Neil Macneale IV
2025-08-27 16:30:48 -07:00
parent c4e5c9ddad
commit b3877a5515
2 changed files with 20 additions and 7 deletions

View File

@@ -68,15 +68,18 @@ func Start() *Pager {
parts := strings.Fields(doltPager)
pagerPath, err = exec.LookPath(parts[0])
if err != nil {
d.Chk.NoError(err)
}
if len(parts) > 1 {
cmd = exec.Command(pagerPath, parts[1:]...)
// If the specified pager is not found, print an error and fall back to less or more
fmt.Fprintf(os.Stderr, "warning: specified pager '%s' not found, falling back to less or more\n", parts[0])
} else {
cmd = exec.Command(pagerPath)
if len(parts) > 1 {
cmd = exec.Command(pagerPath, parts[1:]...)
} else {
cmd = exec.Command(pagerPath)
}
}
} else {
// Fall back to less or more if DOLT_PAGER is not set
}
if cmd == nil {
pagerPath, err = exec.LookPath("less")
if err != nil {
pagerPath, err = exec.LookPath("more")

View File

@@ -36,3 +36,13 @@ export NO_COLOR=1
[[ ! "$output" =~ "commit 17 abc" ]] || false
[ "${#lines[@]}" -eq 3 ]
}
# bats test_tags=no_lambda
@test "pager: gracefully exit when pager doesn't exist" {
skiponwindows "Need to install expect and make this script work on windows."
export DOLT_PAGER="foobar"
run expect $BATS_TEST_DIRNAME/pager.expect
[ "$status" -eq 0 ]
[[ "$output" =~ "warning: specified pager 'foobar' not found, falling back to less or more" ]] || false
}