HBASE-20270 Turned off command help that follows all errors in shell
Signed-off-by: Sean Busbey <busbey@apache.org> (cherry picked from commit 152104ae1ba559c580ffaa083209fd2cfee1050b)
This commit is contained in:
parent
84afd69c63
commit
101055e343
|
@ -21,14 +21,25 @@ require 'shell/formatter'
|
||||||
|
|
||||||
module Shell
|
module Shell
|
||||||
module Commands
|
module Commands
|
||||||
|
# rubocop:disable Metrics/ClassLength
|
||||||
class Command
|
class Command
|
||||||
def initialize(shell)
|
def initialize(shell)
|
||||||
@shell = shell
|
@shell = shell
|
||||||
end
|
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
|
# wrap an execution of cmd to catch hbase exceptions
|
||||||
# cmd - command name to execute
|
# cmd - command name to execute
|
||||||
# args - arguments to pass to the command
|
# args - arguments to pass to the command
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def command_safe(debug, cmd = :command, *args)
|
def command_safe(debug, cmd = :command, *args)
|
||||||
# Commands can overwrite start_time to skip time used in some kind of setup.
|
# Commands can overwrite start_time to skip time used in some kind of setup.
|
||||||
# See count.rb for example.
|
# See count.rb for example.
|
||||||
|
@ -48,7 +59,7 @@ module Shell
|
||||||
puts "ERROR: #{rootCause}"
|
puts "ERROR: #{rootCause}"
|
||||||
puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug
|
puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug
|
||||||
puts
|
puts
|
||||||
puts help
|
puts "For usage try 'help \"#{command_name}\"'"
|
||||||
puts
|
puts
|
||||||
else
|
else
|
||||||
raise rootCause
|
raise rootCause
|
||||||
|
@ -58,6 +69,7 @@ module Shell
|
||||||
@end_time ||= Time.now
|
@end_time ||= Time.now
|
||||||
formatter.output_str(format('Took %.4f seconds', @end_time - @start_time))
|
formatter.output_str(format('Took %.4f seconds', @end_time - @start_time))
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
# Convenience functions to get different admins
|
# Convenience functions to get different admins
|
||||||
# Returns HBase::Admin ruby class.
|
# Returns HBase::Admin ruby class.
|
||||||
|
@ -162,5 +174,6 @@ module Shell
|
||||||
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
||||||
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/ClassLength
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,10 @@ EOF
|
||||||
def command(id, table_cfs)
|
def command(id, table_cfs)
|
||||||
replication_admin.append_peer_tableCFs(id, table_cfs)
|
replication_admin.append_peer_tableCFs(id, table_cfs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def command_name
|
||||||
|
'append_peer_tableCFs'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,10 @@ EOF
|
||||||
def command(id, table_cfs)
|
def command(id, table_cfs)
|
||||||
replication_admin.remove_peer_tableCFs(id, table_cfs)
|
replication_admin.remove_peer_tableCFs(id, table_cfs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def command_name
|
||||||
|
'remove_peer_tableCFs'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,6 +46,10 @@ module Shell
|
||||||
def command(id, exclude_peer_table_cfs = nil)
|
def command(id, exclude_peer_table_cfs = nil)
|
||||||
replication_admin.set_peer_exclude_tableCFs(id, exclude_peer_table_cfs)
|
replication_admin.set_peer_exclude_tableCFs(id, exclude_peer_table_cfs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def command_name
|
||||||
|
'set_peer_exclude_tableCFs'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,10 @@ module Shell
|
||||||
puts peer_table_cfs
|
puts peer_table_cfs
|
||||||
peer_table_cfs
|
peer_table_cfs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def command_name
|
||||||
|
'show_peer_tableCFs'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,24 @@ class ShellCommandsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
# Tests commands from the point of view of the shell to validate
|
||||||
# that the error messages returned to the user are correct
|
# that the error messages returned to the user are correct
|
||||||
|
|
Loading…
Reference in New Issue