From 655658ce3659ffb2a9542a5afb5e186748bb7334 Mon Sep 17 00:00:00 2001 From: WenFeiYi Date: Fri, 19 Jun 2020 23:06:10 +0530 Subject: [PATCH] HBASE-24550 Passing '-h' or '--help' to bin/hbase doesn't do as expected Closes #1930 Signed-off-by: Viraj Jasani --- bin/hbase | 44 ++++++++++++++++++++++++++++---------------- bin/hbase-config.cmd | 10 +++++++++- bin/hbase-config.sh | 4 ++++ bin/hbase.cmd | 9 +++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/bin/hbase b/bin/hbase index 33330a47ddb..697af38ed6d 100755 --- a/bin/hbase +++ b/bin/hbase @@ -57,28 +57,15 @@ bin=`dirname "$0"` bin=`cd "$bin">/dev/null; pwd` -# This will set HBASE_HOME, etc. -. "$bin"/hbase-config.sh - -cygwin=false -case "`uname`" in -CYGWIN*) cygwin=true;; -esac - -# Detect if we are in hbase sources dir -in_dev_env=false -if [ -d "${HBASE_HOME}/target" ]; then - in_dev_env=true -fi - read -d '' options_string << EOF Options: --config DIR Configuration direction to use. Default: ./conf --hosts HOSTS Override the list in 'regionservers' file --auth-as-server Authenticate to ZooKeeper using servers configuration + --help or -h Print this help message EOF -# if no args specified, show usage -if [ $# = 0 ]; then + +show_usage() { echo "Usage: hbase [] []" echo "$options_string" echo "" @@ -108,6 +95,31 @@ if [ $# = 0 ]; then echo " hbtop Run the HBTop tool" echo " version Print the version" echo " CLASSNAME Run the class named CLASSNAME" +} + +if [ "--help" = "$1" ] || [ "-h" = "$1" ]; then + show_usage + exit 0 +fi + +# This will set HBASE_HOME, etc. +. "$bin"/hbase-config.sh + +cygwin=false +case "`uname`" in +CYGWIN*) cygwin=true;; +esac + +# Detect if we are in hbase sources dir +in_dev_env=false +if [ -d "${HBASE_HOME}/target" ]; then + in_dev_env=true +fi + + +# if no args specified, show usage +if [ $# = 0 ]; then + show_usage exit 1 fi diff --git a/bin/hbase-config.cmd b/bin/hbase-config.cmd index 5c1f1860f53..3b7b713abfd 100644 --- a/bin/hbase-config.cmd +++ b/bin/hbase-config.cmd @@ -33,6 +33,14 @@ if "%1" == "--config" ( shift shift ) +if "%1" == "--help" ( + echo Error usage! You should use it like 'hbase --help' or 'hbase -h'; + exit /B 2 +) +if "%1" == "-h" ( + echo Error usage! You should use it like 'hbase --help' or 'hbase -h'; + exit /B 2 +) @rem the root of the hbase installation if not defined HBASE_HOME ( @@ -75,4 +83,4 @@ for %%i in (%0) do ( if not defined HBASE_BIN_PATH ( set HBASE_BIN_PATH=%%~dpi ) -) \ No newline at end of file +) diff --git a/bin/hbase-config.sh b/bin/hbase-config.sh index 2f1a254eb05..806b623ea16 100644 --- a/bin/hbase-config.sh +++ b/bin/hbase-config.sh @@ -84,6 +84,10 @@ do exit 1 fi shift + elif [ "--help" = "$1" ] || [ "-h" = "$1" ] + then + echo "Error usage! You should use it like 'hbase --help' or 'hbase -h'"; + exit 1 else # Presume we are at end of options and break break diff --git a/bin/hbase.cmd b/bin/hbase.cmd index da7bcd9dea8..d5334fc0543 100644 --- a/bin/hbase.cmd +++ b/bin/hbase.cmd @@ -59,6 +59,15 @@ if "%HBASE_BIN_PATH:~-1%" == "\" ( set HBASE_BIN_PATH=%HBASE_BIN_PATH:~0,-1% ) +if "%1" == "--help" ( + goto :print_usage + exit /B 0 +) +if "%1" == "-h" ( + goto :print_usage + exit /B 0 +) + rem This will set HBASE_HOME, etc. set hbase-config-script=%HBASE_BIN_PATH%\hbase-config.cmd call "%hbase-config-script%" %*