You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2022/01/08 04:23:52 UTC
[hbase] branch branch-2 updated: HBASE-26543 correct parsing of shell args with GetoptLong (#4000)
This is an automated email from the ASF dual-hosted git repository.
busbey pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2 by this push:
new 9048507 HBASE-26543 correct parsing of shell args with GetoptLong (#4000)
9048507 is described below
commit 9048507319cd02187993f77f10e250d3c975806a
Author: Sean Busbey <bu...@apache.org>
AuthorDate: Wed Dec 15 14:35:01 2021 -0600
HBASE-26543 correct parsing of shell args with GetoptLong (#4000)
Signed-off-by: Mike Drob <md...@apache.org>
(cherry picked from commit dda337fd9ec8db0a35cdbe0d0627185ec886ffd1)
---
hbase-shell/src/main/ruby/jar-bootstrap.rb | 69 ++++++++++++++----------------
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/hbase-shell/src/main/ruby/jar-bootstrap.rb b/hbase-shell/src/main/ruby/jar-bootstrap.rb
index 03dba74..47f2de4 100644
--- a/hbase-shell/src/main/ruby/jar-bootstrap.rb
+++ b/hbase-shell/src/main/ruby/jar-bootstrap.rb
@@ -78,62 +78,59 @@ def add_to_configuration(c, arg)
c
end
+conf_from_cli = nil
+
+# strip out any config definitions that won't work with GetoptLong
+D_ARG = '-D'.freeze
+ARGV.delete_if do |arg|
+ if arg.start_with?(D_ARG) && arg.include?('=')
+ conf_from_cli = add_to_configuration(conf_from_cli, arg[2..-1])
+ true
+ else
+ false
+ end
+end
+
opts = GetoptLong.new(
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
- [ '--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT ],
- [ '--noninteractive', '-n', GetoptLong::OPTIONAL_ARGUMENT ],
- [ '--top-level-defs', GetoptLong::OPTIONAL_ARGUMENT ],
- [ '--Dkey=value', '-D', GetoptLong::NO_ARGUMENT ]
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
+ ['--debug', '-d', GetoptLong::NO_ARGUMENT],
+ ['--noninteractive', '-n', GetoptLong::NO_ARGUMENT],
+ ['--top-level-defs', GetoptLong::NO_ARGUMENT],
+ ['-D', GetoptLong::REQUIRED_ARGUMENT],
+ ['--return-values', '-r', GetoptLong::NO_ARGUMENT]
)
+opts.ordering = GetoptLong::REQUIRE_ORDER
-found = []
script2run = nil
log_level = org.apache.log4j.Level::ERROR
@shell_debug = false
interactive = true
top_level_definitions = false
-_configuration = nil
-D_ARG = '-D'.freeze
opts.each do |opt, arg|
- case opt || arg
- when '--help' || '-h'
+ case opt
+ when '--help'
puts cmdline_help
+ exit
when D_ARG
- argValue = ARGV.shift || (raise "#{D_ARG} takes a 'key=value' parameter")
- _configuration = add_to_configuration(_configuration, argValue)
- found.push(arg)
- found.push(argValue)
- when arg.start_with?(D_ARG)
- _configuration = add_to_configuration(_configuration, arg[2..-1])
- found.push(arg)
- when '--debug'|| '-d'
+ conf_from_cli = add_to_configuration(conf_from_cli, arg)
+ when '--debug'
log_level = org.apache.log4j.Level::DEBUG
$fullBackTrace = true
@shell_debug = true
- found.push(arg)
puts 'Setting DEBUG log level...'
- when '--noninteractive'|| '-n'
- interactive = false
- found.push(arg)
- when '--return-values' || 'r'
- warn '[INFO] the -r | --return-values option is ignored. we always behave '\
+ when '--noninteractive'
+ interactive = false
+ when '--return-values'
+ warn '[INFO] the -r | --return-values option is ignored. we always behave '\
'as though it was given.'
- found.push(arg)
- when '--top-level-defs'
- top_level_definitions = true
- else
- # Presume it a script. Save it off for running later below
- # after we've set up some environment.
- script2run = arg
- found.push(arg)
- # Presume that any other args are meant for the script.
+ when '--top-level-defs'
+ top_level_definitions = true
end
end
+script2run = ARGV.shift unless ARGV.empty?
-# Delete all processed args
-found.each { |arg| ARGV.delete(arg) }
# Make sure debug flag gets back to IRB
ARGV.unshift('-d') if @shell_debug
@@ -151,7 +148,7 @@ require 'hbase_shell'
require 'shell/formatter'
# Setup the HBase module. Create a configuration.
-@hbase = _configuration.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(_configuration)
+@hbase = conf_from_cli.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(conf_from_cli)
# Setup console
@shell = Shell::Shell.new(@hbase, interactive)