mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
fix(CLI): Ensure to recognize "-v" param as boolean in all cases
This commit is contained in:
parent
496d3574c6
commit
82b95fc492
@ -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
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user