help: have --usage always print a usage line

This commit is contained in:
Mislav Marohnić 2023-07-11 18:54:38 +02:00
parent af9201ea1e
commit 592fe6a087
No known key found for this signature in database
2 changed files with 17 additions and 1 deletions

View file

@ -144,7 +144,11 @@ print_usage() {
local command="$1"
local summary usage help
eval "$(documentation_for "$command")"
[ -z "$usage" ] || echo "$usage"
if [ -n "$usage" ]; then
echo "$usage"
else
echo "Usage: rbenv ${command}"
fi
}
unset usage

View file

@ -71,6 +71,18 @@ SH
assert_success "Usage: rbenv hello <world>"
}
@test "empty usage section" {
mkdir -p "${RBENV_TEST_DIR}/bin"
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
#!shebang
# Summary: Says "hello" to you, from rbenv
echo hello
SH
run rbenv-help --usage hello
assert_success "Usage: rbenv hello"
}
@test "multiline usage section" {
mkdir -p "${RBENV_TEST_DIR}/bin"
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH