HBASE-20270 Turned off command help that follows all errors in shell
Signed-off-by: Sean Busbey <busbey@apache.org>
This commit is contained in:
parent
12c45cb2e8
commit
8a30acf46f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,6 +34,10 @@ module Shell
|
|||
puts peer_table_cfs
|
||||
peer_table_cfs
|
||||
end
|
||||
|
||||
def command_name
|
||||
'show_peer_tableCFs'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue