We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
yargs 17.5.1
when an array option is given a default value, requiresArg no longer works.
requiresArg
example
console.log( yargs(['-s']) .option('s', { type: 'array', default: ['turtles'], requiresArg: true }) .argv );
expected: failure due to not enough args following -s.
actual: success, default value assigned to -s.
more complete example
import yargs from 'yargs'; let SECTION = msg => console.log(`\n======${msg?` ${msg} `:''}======\n`); // should fail, and does SECTION('array + requiresArg'); try { console.log( yargs(['-s']) .option('s', { type: 'array', requiresArg: true }) .exitProcess(false) .argv ); } catch { } // should fail, and does SECTION('string + default + requiresArg'); try { console.log( yargs(['-s']) .option('s', { type: 'string', default: 'turtles', requiresArg: true }) .exitProcess(false) .argv ); } catch { } // should fail, but doesn't SECTION('array + default + requiresArg (missing arg)'); console.log( yargs(['-s']) .option('s', { type: 'array', default: ['turtles'], requiresArg: true }) .argv ); // should succeed, and does SECTION('array + default + requiresArg (with arg)'); console.log( yargs(['-s', 'stank', 'bread']) .option('s', { type: 'array', default: ['turtles'], requiresArg: true }) .argv );
output:
====== array + requiresArg ====== Options: --help Show help [boolean] --version Show version number [boolean] -s [array] Not enough arguments following: s ====== string + default + requiresArg ====== Options: --help Show help [boolean] --version Show version number [boolean] -s [string] [default: "turtles"] Not enough arguments following: s ====== array + default + requiresArg (missing arg) ====== { _: [], s: [ 'turtles' ], '$0': 'yargteststuff.js' } ====== array + default + requiresArg (with arg) ====== { _: [], s: [ 'stank', 'bread' ], '$0': 'yargteststuff.js' }
The text was updated successfully, but these errors were encountered:
@JC3 thank you for the bug report 👍
Sorry, something went wrong.
No branches or pull requests
yargs 17.5.1
when an array option is given a default value,
requiresArg
no longer works.example
expected: failure due to not enough args following -s.
actual: success, default value assigned to -s.
more complete example
output:
The text was updated successfully, but these errors were encountered: