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
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
10 changes: 10 additions & 0 deletions test.js
Expand Up @@ -45,6 +45,16 @@ 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 => {
LitoMore marked this conversation as resolved.
Show resolved Hide resolved
const {stdout} = await execa('./fixture.js', ['bar', '--version']);
LitoMore marked this conversation as resolved.
Show resolved Hide resolved
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