mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 08:50:01 -06:00
Handle bogus pager gracefully
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user