Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/adr-help
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions tests/help-falls-back-to-cat.expected
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions tests/help-falls-back-to-cat.sh
Original file line number Diff line number Diff line change
@@ -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