diff --git a/lib/cli/resolve-input.js b/lib/cli/resolve-input.js index 5f7276301..76c8720eb 100644 --- a/lib/cli/resolve-input.js +++ b/lib/cli/resolve-input.js @@ -6,7 +6,7 @@ const memoizee = require('memoizee'); const parseArgs = require('./parse-args'); const baseArgsSchema = { - boolean: new Set(['version', 'help', 'help-interactive']), + boolean: new Set(['version', 'help', 'help-interactive', 'v']), string: new Set(['config']), alias: new Map([ ['c', 'config'], @@ -18,7 +18,7 @@ module.exports = memoizee(() => { const options = parseArgs(args, baseArgsSchema); const commands = options._; delete options._; - if (!commands.length && options.v === true && !options.version) { + if (!commands.length && options.v && !options.version) { // Ideally we should output version info in whatever context "--version" or "-v" params // are used. Still "-v" is defined also as a "--verbose" alias for some commands. // Support for "--verbose" is expected to go away with diff --git a/test/unit/lib/cli/resolve-input.test.js b/test/unit/lib/cli/resolve-input.test.js index 1a2245801..7414fd96f 100644 --- a/test/unit/lib/cli/resolve-input.test.js +++ b/test/unit/lib/cli/resolve-input.test.js @@ -21,7 +21,6 @@ describe('test/unit/lib/cli/resolve-input.test.js', () => { 'h', '--config', 'conf', - '-v', 'elo', 'other', ], @@ -31,7 +30,7 @@ describe('test/unit/lib/cli/resolve-input.test.js', () => { }); it('should resolve commands', async () => { - expect(data.commands).to.deep.equal(['cmd1', 'cmd2', 'ver', 'h', 'other']); + expect(data.commands).to.deep.equal(['cmd1', 'cmd2', 'ver', 'h', 'elo', 'other']); }); it('should recognize --version as boolean', async () => { @@ -46,8 +45,22 @@ describe('test/unit/lib/cli/resolve-input.test.js', () => { expect(data.options.config).to.equal('conf'); }); - it('should not recognize -v with command', async () => { - expect(data.options.v).to.equal('elo'); + describe('"-v" handling', () => { + before(() => { + resolveInput.clear(); + data = overrideArgv( + { + args: ['serverless', 'cmd1', 'cmd2', '-v', 'ver', 'other'], + }, + () => resolveInput() + ); + }); + it('should not recognize as version alias', async () => { + expect(data.options).to.not.have.property('version'); + }); + it('should recognize as boolean', async () => { + expect(data.options.v).to.equal(true); + }); }); }); describe('when no commands', () => { @@ -66,7 +79,7 @@ describe('test/unit/lib/cli/resolve-input.test.js', () => { expect(data.commands).to.deep.equal([]); }); - it('should recognize -v alias', async () => { + it('should recognize -v as --version alias', async () => { expect(data.options.version).to.equal(true); });