Repository: hbase Updated Branches: refs/heads/HBASE-19064 491eaed53 -> 987eb5455 (forced update)
HBASE-20270 Turned off command help that follows all errors in shell Signed-off-by: Sean Busbey <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/8a30acf4 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/8a30acf4 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/8a30acf4 Branch: refs/heads/HBASE-19064 Commit: 8a30acf46f1614f4253d77bc6cae4170976e9ab2 Parents: 12c45cb Author: Sakthi <[email protected]> Authored: Wed Apr 18 22:25:05 2018 -0700 Committer: Sean Busbey <[email protected]> Committed: Wed Apr 25 15:36:33 2018 -0500 ---------------------------------------------------------------------- hbase-shell/src/main/ruby/shell/commands.rb | 15 ++++++++++++++- .../ruby/shell/commands/append_peer_tableCFs.rb | 4 ++++ .../ruby/shell/commands/remove_peer_tableCFs.rb | 4 ++++ .../shell/commands/set_peer_exclude_tableCFs.rb | 4 ++++ .../ruby/shell/commands/show_peer_tableCFs.rb | 4 ++++ hbase-shell/src/test/ruby/shell/commands_test.rb | 18 ++++++++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/main/ruby/shell/commands.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 85a742e..d60d07c 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 @@ -58,6 +69,7 @@ module Shell @end_time ||= Time.now formatter.output_str(format('Took %.4f seconds', @end_time - @start_time)) end + # rubocop:enable Metrics/AbcSize # Convenience functions to get different admins # Returns HBase::Admin ruby class. @@ -164,5 +176,6 @@ module Shell # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity end + # rubocop:enable Metrics/ClassLength end end http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb ---------------------------------------------------------------------- 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 0dbf2d7..16b1288 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb ---------------------------------------------------------------------- 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 d50b405..595cf32 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/main/ruby/shell/commands/set_peer_exclude_tableCFs.rb ---------------------------------------------------------------------- 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 25be364..ccb1329 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb ---------------------------------------------------------------------- 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 c7b3aab..c2a3f7a 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/8a30acf4/hbase-shell/src/test/ruby/shell/commands_test.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb b/hbase-shell/src/test/ruby/shell/commands_test.rb index 5daf9fa..0106099 100644 --- a/hbase-shell/src/test/ruby/shell/commands_test.rb +++ b/hbase-shell/src/test/ruby/shell/commands_test.rb @@ -37,6 +37,24 @@ class ShellCommandsTest < Test::Unit::TestCase 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
