busbey commented on a change in pull request #4000:
URL: https://github.com/apache/hbase/pull/4000#discussion_r779639725
##########
File path: 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
Review comment:
for those interested in more details here are the docs for Ruby
GetoptLong's ordering:
https://ruby-doc.org/stdlib-3.0.3/libdoc/getoptlong/rdoc/GetoptLong.html#method-i-ordering-3D
specifically, this patch expressly has us use `REQUIRE_ORDER`:
> REQUIRE_ORDER :
>
> Options are required to occur before non-options.
>
> Processing of options ends as soon as a word is encountered that has not
been preceded by an appropriate option flag.
I believe this matches the behavior of our manual cli argument parsing prior
to HBASE-24772.
Note that by default GetoptLong picks an ordering based on an environment
variable we don't set. The default in that case is `PERMUTE` :
> PERMUTE :
>
> Options can occur anywhere in the command line parsed. This is the default
behavior.
>
> Every sequence of words which can be interpreted as an option (with or
without argument) is treated as an option; non-option words are skipped.
This ordering option is why after HBASE-24772, and prior to this patch,
passing in IRB's "ignore .irbrc" flag ( `-f`) would cause our shell to crash
with an "I don't know what that option is supposed to mean".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]