From c0b0dccd3ccc42777350e0644d0c8475403d1478 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/commands.rb | 6 +++++- hbase-shell/src/test/ruby/shell/commands_test.rb | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 85a742e436c1e6234169e59d9bafd4552887f65c..fe3d75dd696bbdbbb207139de86d8d3d6308367a 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -29,6 +29,8 @@ module Shell # wrap an execution of cmd to catch hbase exceptions # cmd - command name to execute # args - arguments to pass to the command + + # rubocop:disable Metrics/AbcSize def command_safe(debug, cmd = :command, *args) # Commands can overwrite start_time to skip time used in some kind of setup. # See count.rb for example. @@ -48,7 +50,9 @@ module Shell puts "ERROR: #{rootCause}" puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug puts - puts help + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + 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..0106099fd772eb586af5569fd68cf771a4557565 100644 --- a/hbase-shell/src/test/ruby/shell/commands_test.rb +++ b/hbase-shell/src/test/ruby/shell/commands_test.rb @@ -36,6 +36,24 @@ 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)