Merge pull request #1515 from rbenv/help-usage

help: have `--usage` always print a usage line
This commit is contained in:
Mislav Marohnić 2023-07-14 23:29:47 +02:00 committed by GitHub
commit 4fec76f267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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