From 12542542d8c124873b0f19b202ed7c6b1754f413 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 | 15 +++++++++++++-- .../main/ruby/shell/commands/append_peer_tableCFs.rb | 4 ++++ .../main/ruby/shell/commands/remove_peer_tableCFs.rb | 4 ++++ .../ruby/shell/commands/set_peer_exclude_tableCFs.rb | 4 ++++ .../src/main/ruby/shell/commands/show_peer_tableCFs.rb | 4 ++++ hbase-shell/src/test/ruby/shell/commands_test.rb | 18 ++++++++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 85a742e436c1e6234169e59d9bafd4552887f65c..520c111cac90243a06b24c7b815cbcb47f9de4ba 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -21,14 +21,25 @@ require 'shell/formatter' module Shell module Commands + # rubocop:disable Metrics/ClassLength class Command def initialize(shell) @shell = shell end + # gets the name that an operator would type into the shell + + def command_name + klass_name = self.class.name.split('::').last + command = klass_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase + 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 +59,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 @@ -104,7 +115,7 @@ module Shell @formatter = formatter end - # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity + # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity def translate_hbase_exceptions(*args) yield 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..16b128832937875896d4c23552d597785fe93877 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,10 @@ EOF def command(id, table_cfs) replication_admin.append_peer_tableCFs(id, table_cfs) end + + def command_name + 'append_peer_tableCFs' + 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..595cf32851c9ed3eb44bcf38c5ece99baf32099f 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,10 @@ EOF def command(id, table_cfs) replication_admin.remove_peer_tableCFs(id, table_cfs) end + + def command_name + 'remove_peer_tableCFs' + 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..ccb1329cfa21b3087df251c450008d6adc446e11 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,10 @@ 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 + 'set_peer_exclude_tableCFs' + 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..c2a3f7a526cc5d6c0696ab68f98f934060e5e41c 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,10 @@ module Shell puts peer_table_cfs peer_table_cfs end + + def command_name + 'show_peer_tableCFs' + 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)