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

A tweak to make flags with default values act as switches when passed without args #11

Merged
merged 1 commit into from
Nov 5, 2014
Merged

A tweak to make flags with default values act as switches when passed without args #11

merged 1 commit into from
Nov 5, 2014

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Oct 19, 2014

When a script is configured with:

opts = Trollop::options do
  opts :argwithdefault, "An Argument w/ a default", :default => "default value"
end

Then trying:

command --arg-with-default

Seems like we should get the default value rather than an error.

via gitorius

assert_equal "default_string", opts[:argd]

opts = @p.parse(%w( --argd ))
assert opts[:argd_given]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_string goes in there whether we have params << [opts[:default]] or next
unfortunately, opts[:argd_given] doesn't get populated.

feels like there should be a way to take the default without populating the params.


Need to digest more to ensurethe underlying meaning of "#{param}_given" is not modified here.
It means the user supplied a value. But if the user says "yea, yea. Just use the default value," then I guess this is the user giving the value.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) when pulling 42b6912 on kbrock:default_with_switch into 1b132c1 on ManageIQ:master.

kbrock added a commit that referenced this pull request Nov 5, 2014
A tweak to make flags with default values act as switches when passed without args
@kbrock kbrock merged commit 1cf43e2 into ManageIQ:master Nov 5, 2014
@kbrock kbrock deleted the default_with_switch branch November 5, 2014 00:10
Fryguy pushed a commit to Fryguy/optimist that referenced this pull request Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants