From 927a6250e88dcca89fd198f40bb12b6d79716a6c 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 | 12 +++++++++++- .../main/ruby/shell/commands/append_peer_tableCFs.rb | 6 ++++++ .../main/ruby/shell/commands/remove_peer_tableCFs.rb | 6 ++++++ .../ruby/shell/commands/set_peer_exclude_tableCFs.rb | 6 ++++++ .../src/main/ruby/shell/commands/show_peer_tableCFs.rb | 6 ++++++ hbase-shell/src/test/ruby/shell/commands_test.rb | 18 ++++++++++++++++++ 6 files changed, 53 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..5074ed170c920009c8c229ca7c892c5a0448fa32 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -26,9 +26,19 @@ module Shell @shell = shell end + # get command name + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + command + end + # 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 +58,7 @@ module Shell puts "ERROR: #{rootCause}" puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug puts - puts help + puts "For usage try 'help \"#{command_name}\"'" puts else raise rootCause diff --git a/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb index 0dbf2d72dd0f0e98c346060eb3d9ca70e5edea29..d452151a8212ebcc4b45b47b21950b0aa315f8c7 100644 --- a/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb @@ -34,6 +34,12 @@ EOF def command(id, table_cfs) replication_admin.append_peer_tableCFs(id, table_cfs) end + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + command + end end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb index d50b40546fd7e361e9001ab95bc4196268a0fb98..58d2e4a2a363084b3901ad99034074d5c20f7e4d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb @@ -35,6 +35,12 @@ EOF def command(id, table_cfs) replication_admin.remove_peer_tableCFs(id, table_cfs) end + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + command + end end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/set_peer_exclude_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/set_peer_exclude_tableCFs.rb index 25be364237b7d16e2ce760cfb6354406c2d39b62..8813a86d50bd8fa35f48db0c87963df8909ac0c8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_peer_exclude_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_exclude_tableCFs.rb @@ -46,6 +46,12 @@ module Shell def command(id, exclude_peer_table_cfs = nil) replication_admin.set_peer_exclude_tableCFs(id, exclude_peer_table_cfs) end + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + command + end end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb index c7b3aab4e47ba3d0966f0616b27216cb29783770..8e7cfdc2c8e1cf7aa8c0e2c888dbeb6ae18c1576 100644 --- a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb @@ -34,6 +34,12 @@ module Shell puts peer_table_cfs peer_table_cfs end + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase.gsub(/_cfs/, 'CFs') + command + end end end end 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)