Skip to content

Commit

Permalink
Don't add --help if -V. Fixes #273
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Oct 13, 2020
1 parent 92fe997 commit 0807275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/BinUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var createSubCommands = function(dir, defArgs, descTs, opts) {
program = createCommands(_.values(componentNames), defArgs, descTs, opts);

if (!componentNames[component]) {
const showVersion = process.argv.includes('--version') || process.argv.includes('-V');
var config = utils.getConfig();
if (inferrable && config) { // Try to infer the component. Assume name is provided
var name = process.argv[2],
Expand All @@ -100,7 +101,7 @@ var createSubCommands = function(dir, defArgs, descTs, opts) {
}

process.argv.splice(2, 0, rAlias[component] || component || '--help');
} else if (process.argv.indexOf('--version') === -1) {
} else if (!showVersion) {
// Show the help message
process.argv = [
process.argv[0],
Expand Down
19 changes: 19 additions & 0 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Testing the command line interfaces for the commands
'use strict';

const {version} = require('../package.json');
var spawn = require('child_process').spawn,
path = require('path'),
fs = require('fs'),
Expand Down Expand Up @@ -187,6 +188,24 @@ describe('cli', function() {
});
});

describe('version info', function() {
it('should show version on --version', done => {
var testFn = function(res, err, done) {
assert(res.includes(version));
done();
};
testCliCall(['--version'], testFn, done);
});

it('should show version on -V', done => {
var testFn = function(res, err, done) {
assert(res.includes(version));
done();
};
testCliCall(['--version'], testFn, done);
});
});

describe('--package-name option on import', function() {
var binDir = path.join(__dirname, '..', 'bin'),
files = fs.readdirSync(binDir),
Expand Down

0 comments on commit 0807275

Please sign in to comment.