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 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
16 changes: 6 additions & 10 deletions test.js
Expand Up @@ -45,16 +45,6 @@ test('spawn cli and not show version', async t => {
t.is(stdout, 'version\nautoVersion\nmeow\ncamelCaseOption');
});

test('spwan cli test input without version output', async t => {
const {stdout} = await execa('./fixture.js', ['bar', '--version']);
t.is(stdout, 'version\nmeow\ncamelCaseOption');
});

test('spwan cli test input without help output', async t => {
const {stdout} = await execa('./fixture.js', ['bar', '--help']);
t.is(stdout, 'help\nmeow\ncamelCaseOption');
});

test('spawn cli and show help screen', async t => {
const {stdout} = await execa('./fixture.js', ['--help']);
t.is(stdout, indentString('\nCustom description\n\nUsage\n foo <input>\n\n', 2));
Expand Down Expand Up @@ -229,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');
});