From 57a68bcbe58ba700e266eb6c84011b5c98d18feb Mon Sep 17 00:00:00 2001 From: Sakthi Date: Wed, 18 Apr 2018 22:25:05 -0700 Subject: [PATCH] HBASE-20270 Turned off command help that follows all errors in shell --- hbase-shell/src/main/ruby/shell.rb | 2 +- hbase-shell/src/main/ruby/shell/commands.rb | 4 ++-- hbase-shell/src/test/ruby/shell/commands_test.rb | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index ab07a79b985d9a724db607dbcd7fd24ce2c2e536..0741ed2549435e9e9ca3094b86e56b71a9d3bae5 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -145,7 +145,7 @@ module Shell # method_name - name of the method on the command to call. Defaults to just 'command' # args - to be passed to the named method def internal_command(command, method_name = :command, *args) - command_instance(command).command_safe(debug, method_name, *args) + command_instance(command).command_safe(debug, command, method_name, *args) end def print_banner diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 85a742e436c1e6234169e59d9bafd4552887f65c..9655d8527eaa48f1ff3a3579a53fc270c3255e68 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -29,7 +29,7 @@ module Shell # wrap an execution of cmd to catch hbase exceptions # cmd - command name to execute # args - arguments to pass to the command - def command_safe(debug, cmd = :command, *args) + def command_safe(debug, command, cmd = :command, *args) # Commands can overwrite start_time to skip time used in some kind of setup. # See count.rb for example. @start_time = Time.now @@ -48,7 +48,7 @@ module Shell puts "ERROR: #{rootCause}" puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug puts - puts help + puts "For usage try 'help \"#{command}\"'" puts else raise rootCause diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb b/hbase-shell/src/test/ruby/shell/commands_test.rb index 5daf9fa7cd56db5d97cde57d69a41a32a39b5999..41ac1c65e9158a1364f9fd14aec77b01528482da 100644 --- a/hbase-shell/src/test/ruby/shell/commands_test.rb +++ b/hbase-shell/src/test/ruby/shell/commands_test.rb @@ -36,6 +36,25 @@ class ShellCommandsTest < Test::Unit::TestCase end end +## +# Tests whether erroneous command input suggests the right way to invoke +# help method of the command + +class ShellCommandsErrorTest < Test::Unit::TestCase + include Hbase::TestHelpers + + def setup + setup_hbase + @shell.interactive = true + end + + define_test 'Erroneous command input should suggest help' do + name = :create + output = capture_stdout{ @shell.command(name) } + assert_match(/For usage try 'help "#{name}"'/, output) + end +end + ## # Tests commands from the point of view of the shell to validate # that the error messages returned to the user are correct -- 2.15.1 (Apple Git-101)