-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PUP-11693) Global OptionParser ignores partially matched invalid params #9313
Conversation
Still need to add the warning when a partial match is detected, I forgot to do that today....it'll be a tomorrow problem |
8e15ed3
to
5bf2a0c
Compare
Puppet accepts partial matches after my changes:
Before my changes it did not:
|
The only thing that I think might be a nice-to-have-but-not-necessary is some text to tell you which option passed in is the partial match. If you think that is a good idea you should go for it, otherwise I think you should just merge it @AriaXLi ! |
This commit modifies how partial matches are handled when parsing global command line options. Before, Puppet would accept and do nothing with options global options that use '-' instead of '_'. For example, it would accept '--show-diff' and do nothing when the correct name is '--show_diff'. With this change, while handling any global options given in the command line options, if the command line option does not match existing global options, it will convert '-' to '_' and vice versa. Then, check if that matches a valid global option. Additionally, if the command line option needs to convert '-' to '_' or vice versa, Puppet will also warn to let the user know a partial match was detected and that this behavior will be deprecated in Puppet 9.
@long["[no-]#{::Regexp.last_match(1)}"] | ||
possible_match = @long["[no-]#{::Regexp.last_match(1)}"] | ||
if !possible_match | ||
Puppet.warning("Partial argument match detected. Partial argument matching will be deprecated in Puppet 9.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to tell users what they should do to remove the warning. Also recommend using the depreciation_warning
method. Maybe something like
Puppet.warning("Partial argument match detected. Partial argument matching will be deprecated in Puppet 9.") | |
Puppet.deprecation_warning("Partial argument match detected. The correct argument is '#{...}'. Partial argument matching behavior is deprecated and will be removed in a future release.") |
possible_match = @long["[no-]#{::Regexp.last_match(1)}"] | ||
if !possible_match | ||
Puppet.warning _("Partial argument match detected: %{arg}. Partial argument matching will be deprecated in Puppet 9.") % { arg: arg } | ||
@long["[no-]#{::Regexp.last_match(1).tr('-', '_')}"] || @long["[no-]#{::Regexp.last_match(1).tr('_', '-')}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I left a comment, but it was marked as "pending" so maybe it wasn't visible? In any case, I think there are a couple adjustments needed:
-
The warning is triggered anytime an application-specific option is given:
$ bundle exec puppet apply --execute "notice(0)" Warning: Partial argument match detected: --execute. Partial argument matching will be deprecated in Puppet 9.
I think we only want to trigger the warning if an argument is given that doesn't match a global option, but it does match one of the translated versions. So
--execute
is not a global option (it's specific to theapply
application) and shouldn't trigger the warning. The argument--show-diff
is also not a global option, but it does match the translated version--show_diff
. So in that case we do want to print the warning. -
If the warning is triggered, it would be good to specify what option the user should be using, so they can self-correct. For example, if a class expects an argument of type
String
, but you pass it anInteger
, we print both the expected and given types:Class[One]: parameter 'a' expects a String value, got Integer
-
Could you use
Puppet.deprecation_warning
instead ofPuppet.warning
so that the deprecation (along with all other deprecations) can be suppressed usingpuppet apply --disable_warnings deprecations ...
? -
Technically, partial argument matches are deprecated now (as of this PR) and the functionality will be removed in a future release. For example, this is the message we print for deprecated puppet applications:
puppet/lib/puppet/application/face_base.rb
Line 255 in e9bccae
Puppet.deprecation_warning(_("'puppet %{face}' is deprecated and will be removed in a future release") % { face: @face.name })
This commit modifies how partial matches are handled when parsing global command line options. Before, Puppet would accept and do nothing with options global options that use '-' instead of '_'. For example, it would accept '--show-diff' and do nothing when the correct name is '--show_diff'.
With this change, while handling any global options given in the command line options, if the command line option does not match existing global options, it will convert '-' to '' and vice versa. Then, check if that matches a valid global option. Additionally, if the command line option needs to convert '-' to '' or vice versa, Puppet will also warn to let the user know a partial match was detected and this behavior will be deprecated in Puppet 9.