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

Only consider enabling autoHelp/autoVersion in case there is only one argument in process.argv #114

Merged
merged 9 commits into from Jun 12, 2019
Merged
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -96,11 +96,11 @@ module.exports = (helpText, options) => {
process.exit();
};

if (argv.version && options.autoVersion) {
if (argv.version && argv._.length === 0 && options.autoVersion) {
showVersion();
}

if (argv.help && options.autoHelp) {
if (argv.help && argv._.length === 0 && options.autoHelp) {
showHelp(0);
}

Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -10,8 +10,8 @@
- Parses arguments
- Converts flags to [camelCase](https://github.com/sindresorhus/camelcase)
- Negates flags when using the `--no-` prefix
- Outputs version when `--version`
- Outputs description and supplied help text when `--help`
- Outputs version when only the `--version`
LitoMore marked this conversation as resolved.
Show resolved Hide resolved
- Outputs description and supplied help text when only the `--help`
- Makes unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail
- Sets the process title to the binary name defined in package.json

Expand Down
6 changes: 6 additions & 0 deletions test.js
Expand Up @@ -219,3 +219,9 @@ test('grouped flags work', t => {
t.is(flags.c, undefined);
t.is(flags.l, undefined);
});

test('only show verson/help if `cli.input.length === 0`', t => {
t.is(meow({argv: ['bar', '--version']}).input[0], 'bar');
t.is(meow({argv: ['bar', '--help']}).input[0], 'bar');
t.is(meow({argv: ['bar', '--version', '--help']}).input[0], 'bar');
});