Skip to content
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

Long options that start with --no-* are negated even when its explicitly defined as an option #48

Open
majormoses opened this issue Aug 19, 2018 · 1 comment
Labels
Type: Bug Does not work as expected.

Comments

@majormoses
Copy link

majormoses commented Aug 19, 2018

Version:

mixlib-cli-1.7.0

Environment:

Unsure see: sensu-plugins/sensu-plugins-disk-checks#94

Scenario:

Use an arg such as --no-smart-capable-disks with a -

Steps to Reproduce:

  1. clone repo: https://github.com/sensu-plugins/sensu-plugins-disk-checks
  2. run bundle
  3. run script:
$ bundle exec ./bin/check-smart.rb --no-smart-capable-disks
Check failed to run: undefined method `to_sym' for false:FalseClass
Did you mean?  to_s, ["/home/babrams/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:290:in `block (3 levels) in opt_parser'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1552:in `block in parse_in_order'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1538:in `catch'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1538:in `parse_in_order'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1532:in `order!'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1626:in `permute!'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/2.4.0/optparse.rb:1648:in `parse!'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:230:in `parse_options'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:13:in `initialize'", "./bin/check-smart.rb:138:in `initialize'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:57:in `new'", "/home/babrams/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"]

Expected Result:

Argument should work

Actual Result:

It blows up and does not parse the arguments properly

@majormoses majormoses changed the title Option names can not include - in them Option names can not include - in them when boolean values Aug 19, 2018
@majormoses majormoses changed the title Option names can not include - in them when boolean values Option names can not include - in them when boolean values are used Aug 19, 2018
@majormoses majormoses changed the title Option names can not include - in them when boolean values are used Long options that start with --no-* are negated even when its explicitly defined as an option Aug 25, 2018
@majormoses
Copy link
Author

majormoses commented Aug 25, 2018

After doing a bit more digging here it would appear that the issue happens when the long option starts with --no-* it automatically attempts to negate an option assuming its boolean. I am not sure how to solve this but maybe we can put some validation in during the option building. Minimally I think this behavior needs to be documented.

@tas50 tas50 added the Type: Bug Does not work as expected. label Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Does not work as expected.
Projects
None yet
Development

No branches or pull requests

2 participants