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

Problem with short operations + underscores #37

Open
rlpowell opened this issue Jan 27, 2015 · 3 comments
Open

Problem with short operations + underscores #37

rlpowell opened this issue Jan 27, 2015 · 3 comments

Comments

@rlpowell
Copy link

Given:

  parser = Trollop::Parser.new do
    opt :silent, %q{Causes the script to not ask any questions, instead all questions turn into email + abort; used by cron}, :short => 's'
    opt :region, %q{Causes the script only work on the listed region}, :short => 'r', :type => String
    opt :noinst, %q{Causes the script to skip the checking of all instances}, :short => 'i'
  end

Running it with -i gives us:

  {:silent=>false,
   :region=>nil,
   :noinst=>true,
   :help=>false,
   :noinst_given=>true}

However, given:

  parser = Trollop::Parser.new do
    opt :silent, %q{Causes the script to not ask any questions, instead all questions turn into email + abort; used by cron}, :short => 's'
    opt :region, %q{Causes the script only work on the listed region}, :short => 'r', :type => String
    opt :no_instances, %q{Causes the script to skip the checking of all instances}, :short => 'i'
  end

which is what I had originally, running it with -i gives:

  {:silent=>false,
   :region=>nil,
   :no_instances=>false,
   :help=>false,
   :no_instances_given=>true}

which strikes me as wrong.

@Fryguy
Copy link
Member

Fryguy commented Jan 27, 2015

There is special logic for flags starting with 'no' to account for
supporting negation of normal flags. I think you can specify a default to
get your desired affect. Another option is to code for the positive and
set a default.

See this blog post for more detail.
http://masanjin.net/blog/trollop-2.0-released
Does that help explain it?
On Jan 26, 2015 9:48 PM, "rlpowell" [email protected] wrote:

Given:

parser = Trollop::Parser.new do
opt :silent, %q{Causes the script to not ask any questions, instead all questions turn into email + abort; used by cron}, :short => 's'
opt :region, %q{Causes the script only work on the listed region}, :short => 'r', :type => String
opt :noinst, %q{Causes the script to skip the checking of all instances}, :short => 'i'
end

Running it with -i gives us:

{:silent=>false,
:region=>nil,
:noinst=>true,
:help=>false,
:noinst_given=>true}

However, given:

parser = Trollop::Parser.new do
opt :silent, %q{Causes the script to not ask any questions, instead all questions turn into email + abort; used by cron}, :short => 's'
opt :region, %q{Causes the script only work on the listed region}, :short => 'r', :type => String
opt :no_instances, %q{Causes the script to skip the checking of all instances}, :short => 'i'
end

which is what I had originally, running it with -i gives:

{:silent=>false,
:region=>nil,
:no_instances=>false,
:help=>false,
:no_instances_given=>true}

which strikes me as wrong.


Reply to this email directly or view it on GitHub
#37.

@rlpowell
Copy link
Author

That does, although now the bug is "this doesn't seem to be mentioned in the documentation anywhere" :)

I'm looking at http://www.rubydoc.info/gems/trollop/2.1.1 and http://www.rubydoc.info/gems/trollop/2.1.1/Trollop/Parser

@kbrock
Copy link
Member

kbrock commented Jan 27, 2015

@ripowell thanks for bringing this up. Any suggestions for the docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants