From 06e4f1b682334560f291cd0a759ee7b91dd21e9c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 14:46:02 -0500 Subject: [PATCH 1/3] explicit --version flag Without it, it falls back to `--version` being executed as a subcommand, which works but isn't obvious --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 609eda11..b65ca112 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -97,7 +97,7 @@ case "$command" in } >&2 exit 1 ;; --v ) +-v | --version ) exec rbenv---version ;; -h | --help ) From 2c4dd63f777ac2219dd21b806b1d422b897d64be Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 14:51:10 -0500 Subject: [PATCH 2/3] handle --help for subcommands If subcommand is provided (and exists) and its first arg is -h/--help, go ahead and intercept the call; redirecting to rbenv-help This means subcommands and plugins need not handle --help flag themselves --- libexec/rbenv | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index b65ca112..a7c4cc5a 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -111,6 +111,10 @@ case "$command" in fi shift 1 - exec "$command_path" "$@" + if [ "$1" = --help ]; then + exec rbenv-help "$command" + else + exec "$command_path" "$@" + fi ;; esac From d7ca2aba2ac0c986b0232a9592a33da2823bc81d Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 17 Nov 2015 15:01:33 -0500 Subject: [PATCH 3/3] add --help to subcommand completions ensure subcommand exists, then include --help in its completion output --- libexec/rbenv-completions | 4 ++++ test/completions.bats | 9 +++++++-- test/exec.bats | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 196212e4..4cb020cf 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -11,6 +11,10 @@ if [ -z "$COMMAND" ]; then fi COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" + +# --help is provided automatically +echo --help + if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" diff --git a/test/completions.bats b/test/completions.bats index 9091f082..6871cf5e 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -13,7 +13,7 @@ create_command() { create_command "rbenv-hello" "#!$BASH echo hello" run rbenv-completions hello - assert_success "" + assert_success "--help" } @test "command with completion support" { @@ -25,7 +25,11 @@ else exit 1 fi" run rbenv-completions hello - assert_success "hello" + assert_success + assert_output <