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

Allow multi-flag parameters #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

akhoury6
Copy link
Contributor

@akhoury6 akhoury6 commented Apr 18, 2024

Some tools need to allow the repeated input of certain valueless parameters. One such example is the use of v for verbose, where the addition of more v's increases the verbosity of the output. This behavior can be seen in tools such as curl and ssh.

Prior to this change, when the :multi option was passed in to a :flag or :boolean parameter, the parser would return either a a true value or an empty array depending on if the flag was passed in the command line or not. This is an unusual paradigm and provides no extra functionality over regular :flag parameters.

After this change, the :flag with :multi set will instead count the number of times the flag was passed. Flag options without :multi set still exhibit the original behavior of simple true/false values.

Example config:

opts = Optimist::options do
    opt :verbose, "Enables verbose output. Twice will enable very-verbose output", multi: true
end

Before change:

$ mytool
{:verbose => []}

$ mytool -vvv
{:verbose => true}

After change:

$ mytool
{:verbose => 0}

$ mytool -vvv
{:verbose => 3}

Some tools need to allow the repeated input of certain valueless parameters. One such example is the use of `v` for `verbose`, where the addition of more v's increases the verbosity of the output. This behavior can be seen in tools such as curl and ssh.

Prior to this change, when the `:multi` option was passed in to a `:flag` or `:boolean` parameter, the parser would return either a a `true` value or an empty array depending on if the flag was passed in the command line or not.

After this change, the `:flag` with `:multi` set will instead count the number of times the flag was passed. Flag options without `:multi` set still exhibit the original behavior of simple `true`/`false` values.

Example config:
```ruby
opts = Optimist::options do
    opt :verbose, "Enables verbose output. Twice will enable very-verbose output", multi: true
end
```

Before change:
```
$ mytool
{:verbose => []}

$ mytool -vvv
{:verbose => true}
```

After change:
```
$ mytool
{:verbose => 0}

$ mytool -vv
{:verbose => 3}
```
@akhoury6
Copy link
Contributor Author

Just a few moments, I'll have the tests sorted out. Forgot about them.

@akhoury6
Copy link
Contributor Author

The remaining failures seem to be unrelated, and are the same failing tests as in the other PR that I submitted.

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

Successfully merging this pull request may close these issues.

2 participants