Repository: hbase Updated Branches: refs/heads/branch-1 28ebd29f0 -> 99306bba7 refs/heads/branch-1.4 9519ec2ea -> 83bbad8bd
HBASE-19770 Separate command return values from interactive shells Uses a new option to the shell to specify that return values are unwanted instead of overloading the interactive option. Enable return_values when the shell is non-interactive. Includes addendum "Replace `if not` with `unless`" Signed-off-by: Apekshit Sharma <[email protected]> Signed-off-by: Mike Drob <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/99306bba Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/99306bba Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/99306bba Branch: refs/heads/branch-1 Commit: 99306bba7799416c9da2f3127c1612c58b016651 Parents: 28ebd29 Author: Josh Elser <[email protected]> Authored: Thu Jan 11 14:47:13 2018 -0500 Committer: Josh Elser <[email protected]> Committed: Thu Feb 15 14:43:57 2018 -0500 ---------------------------------------------------------------------- bin/hirb.rb | 8 +++++++- hbase-shell/src/main/ruby/shell.rb | 14 +++++++++++--- .../src/test/ruby/shell/noninteractive_test.rb | 2 +- hbase-shell/src/test/ruby/test_helper.rb | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/99306bba/bin/hirb.rb ---------------------------------------------------------------------- diff --git a/bin/hirb.rb b/bin/hirb.rb index 52343ca..984cfe2 100644 --- a/bin/hirb.rb +++ b/bin/hirb.rb @@ -59,12 +59,15 @@ Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]] -n | --noninteractive Do not run within an IRB session and exit with non-zero status on first error. + -r | --return-values Include return values from commands + executed in the shell. HERE found = [] script2run = nil log_level = org.apache.log4j.Level::ERROR @shell_debug = false interactive = true +return_values = false for arg in ARGV if arg == '-h' || arg == '--help' puts cmdline_help @@ -78,6 +81,9 @@ for arg in ARGV elsif arg == '-n' || arg == '--noninteractive' interactive = false found.push(arg) + elsif arg == '-r' || arg == '--return-values' + return_values = true + found.push(arg) else # Presume it a script. Save it off for running later below # after we've set up some environment. @@ -112,7 +118,7 @@ require 'shell/formatter' @hbase = Hbase::Hbase.new # Setup console -@shell = Shell::Shell.new(@hbase, interactive) +@shell = Shell::Shell.new(@hbase, interactive, return_values) @shell.debug = @shell_debug # Add commands to this namespace http://git-wip-us.apache.org/repos/asf/hbase/blob/99306bba/hbase-shell/src/main/ruby/shell.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 2c748e2..99ba768 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -71,14 +71,19 @@ module Shell class Shell attr_accessor :hbase attr_accessor :interactive + attr_accessor :return_values alias interactive? interactive + alias return_values? return_values @debug = false attr_accessor :debug - def initialize(hbase, interactive=true) + def initialize(hbase, interactive = true, return_values = !interactive) self.hbase = hbase self.interactive = interactive + self.return_values = return_values + # If we're in non-interactive mode, force return_values + self.return_values = true unless self.interactive end def hbase_admin @@ -133,9 +138,12 @@ module Shell ::Shell.commands[command.to_s].new(self) end - #call the method 'command' on the specified command + # call the method 'command' on the specified command + # If return_values is false, then we suppress the return value. The command + # should have printed relevant output. def command(command, *args) - internal_command(command, :command, *args) + ret = internal_command(command, :command, *args) + ret if return_values end # call a specific internal method in the command instance http://git-wip-us.apache.org/repos/asf/hbase/blob/99306bba/hbase-shell/src/test/ruby/shell/noninteractive_test.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/test/ruby/shell/noninteractive_test.rb b/hbase-shell/src/test/ruby/shell/noninteractive_test.rb index 65c0dad..4fcdee2 100644 --- a/hbase-shell/src/test/ruby/shell/noninteractive_test.rb +++ b/hbase-shell/src/test/ruby/shell/noninteractive_test.rb @@ -20,7 +20,7 @@ require 'shell' class NonInteractiveTest < Test::Unit::TestCase def setup @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration) - @shell = Shell::Shell.new(@hbase, false) + @shell = Shell::Shell.new(@hbase, false, true) end define_test "Shell::Shell noninteractive mode should throw" do http://git-wip-us.apache.org/repos/asf/hbase/blob/99306bba/hbase-shell/src/test/ruby/test_helper.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb index 61015b7..8dca199 100644 --- a/hbase-shell/src/test/ruby/test_helper.rb +++ b/hbase-shell/src/test/ruby/test_helper.rb @@ -43,7 +43,7 @@ module Hbase def setup_hbase hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration) - @shell = ::Shell::Shell.new(hbase) + @shell = ::Shell::Shell.new(hbase, interactive = false, return_values = true) end def shutdown
