From 60603e422c0bbe404703a47c8394b877f72da66e Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Wed, 17 Jun 2026 15:32:29 -0700 Subject: [PATCH] Fix help fallback when more is unavailable Reimplements the intent of npryce/adr-tools#146 with an explicit pager fallback chain that preserves ADR_PAGER and PAGER. Co-authored-by: Abner Rolim Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- src/adr-help | 20 +++++++++++-- tests/help-falls-back-to-cat.expected | 41 +++++++++++++++++++++++++++ tests/help-falls-back-to-cat.sh | 9 ++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 tests/help-falls-back-to-cat.expected create mode 100644 tests/help-falls-back-to-cat.sh diff --git a/src/adr-help b/src/adr-help index ecd0ef5..9e5bb17 100755 --- a/src/adr-help +++ b/src/adr-help @@ -8,9 +8,23 @@ eval "$($(dirname $0)/adr-config)" ## Otherwise lists the available commands. ## ## Uses the environment variables ADR_PAGER or PAGER (in that order) to -## specify the command to be used to display the help text. The default -## pager is: more. +## specify the command to be used to display the help text. If neither is set, +## more, less, or cat is used, in that order. -pager="${ADR_PAGER:-${PAGER:-more}}" +if [ -n "$ADR_PAGER" ] +then + pager="$ADR_PAGER" +elif [ -n "$PAGER" ] +then + pager="$PAGER" +elif command -v more >/dev/null 2>&1 +then + pager=more +elif command -v less >/dev/null 2>&1 +then + pager=less +else + pager=cat +fi ("$adr_bin_dir/_adr_help" "$@") | $pager diff --git a/tests/help-falls-back-to-cat.expected b/tests/help-falls-back-to-cat.expected new file mode 100644 index 0000000..a2e7509 --- /dev/null +++ b/tests/help-falls-back-to-cat.expected @@ -0,0 +1,41 @@ +adr_bin=$(dirname "$(command -v adr)") +dirname "$(command -v adr)" +command -v adr +tmpbin=$(pwd)/bin-without-more +pwd +mkdir "$tmpbin" +for cmd in bash sh awk sed grep find sort head cut tr date mkdir mv cat basename dirname pwd getopt +do + ln -s "$(command -v "$cmd")" "$tmpbin/$cmd" +done +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" +command -v "$cmd" + +PATH="$tmpbin:$adr_bin" ADR_PAGER= PAGER= adr help +usage: adr help COMMAND [ARG] ... +COMMAND is one of: + help + new + link + list + init + config + generate + upgrade-repository +Run 'adr help COMMAND' for help on a specific command. diff --git a/tests/help-falls-back-to-cat.sh b/tests/help-falls-back-to-cat.sh new file mode 100644 index 0000000..324438c --- /dev/null +++ b/tests/help-falls-back-to-cat.sh @@ -0,0 +1,9 @@ +adr_bin=$(dirname "$(command -v adr)") +tmpbin=$(pwd)/bin-without-more +mkdir "$tmpbin" +for cmd in bash sh awk sed grep find sort head cut tr date mkdir mv cat basename dirname pwd getopt +do + ln -s "$(command -v "$cmd")" "$tmpbin/$cmd" +done + +PATH="$tmpbin:$adr_bin" ADR_PAGER= PAGER= adr help