From e2e474c59ddecadffa7c318ee2fe2f23d4cd25a5 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sat, 29 Dec 2012 12:12:47 -0600 Subject: [PATCH] Add `rbenv help --usage` --- libexec/rbenv-help | 24 +++++++++++++++++++++--- libexec/rbenv-whence | 2 +- libexec/rbenv-which | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 00eaab15..fd7f1816 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -110,9 +110,23 @@ print_help() { fi } -if [ -z "$1" ]; then - rbenv---version +print_usage() { + local command="$1" + local summary usage help + eval "$(documentation_for "$command")" + [ -z "$usage" ] || echo "$usage" +} + +unset usage +if [ "$1" = "--usage" ]; then + usage="1" + shift +fi + +if [ -z "$1" ] || [ "$1" == "rbenv" ]; then + [ -n "$usage" ] || rbenv---version echo "Usage: rbenv []" + [ -z "$usage" ] || exit echo echo "Some useful rbenv commands are:" print_summaries commands rehash global local shell version versions which whence @@ -122,7 +136,11 @@ if [ -z "$1" ]; then else command="$1" if [ -n "$(command_path "$command")" ]; then - print_help "$command" + if [ -n "$usage" ]; then + print_usage "$command" + else + print_help "$command" + fi else echo "rbenv: no such command \`$command'" >&2 exit 1 diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 5bb499b9..6c3486ca 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -30,7 +30,7 @@ whence() { RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - rbenv-help whence | head -1 >&2 + rbenv-help --usage whence >&2 exit 1 fi diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 6c62f5ca..7fa32a9f 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -52,7 +52,7 @@ RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then - rbenv-help which | head -1 >&2 + rbenv-help --usage which >&2 exit 1 fi