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

Commits on Apr 18, 2024

  1. Allow multi-flag parameters

    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 committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    07e97f0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1809e89 View commit details
    Browse the repository at this point in the history