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

Add string[] to options defaultValue type #1721

Merged
merged 1 commit into from
May 9, 2022

Commits on Apr 20, 2022

  1. Add string[] to options defaultValue type

    option and requiredOption's defaultValue parameter was `string |
    boolean` but the default for a variadic option should be an array.
    
    ```
    program.option('--var <args...>', 'variadic arguments', ['1'])
    program.parse([])
    > { var: ['1'] }
    
    program.parse(['--var', '1', '2'])
    > { var: ['1', '2'] }
    ```
    
    If you use a string default you have to handle opts that are strings
    ```
    // with a string arg the default value is a string.
    program.option('--var <args...>', 'variadic arguments', '1')
    program.parse([])
    > { var: '1' }
    
    program.parse(['--var', '1', '2'])
    > { var: ['1', '2'] }
    ```
    
    `unknown` matches the jsdoc comment and the typings for argument(name:
    string, description?: string, defaultValue?: unknown): this` but
    conflicts with other `option` overloads.
    
    commander will pass thru any defaultValue to parse opts so `any` or
    `unknown` are good choices, but `string | boolean | string[]` reflects
    the values that commander will return when it parses arguments without a
    coerce function.
    Caleb ツ Everett committed Apr 20, 2022
    Configuration menu
    Copy the full SHA
    8ca3c3d View commit details
    Browse the repository at this point in the history