mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
fix(CLI): Recognize "-s" as "--stage" alias, when expected
This commit is contained in:
parent
8db64a1f31
commit
9ae604591d
@ -5,12 +5,14 @@
|
||||
const memoizee = require('memoizee');
|
||||
const parseArgs = require('./parse-args');
|
||||
|
||||
const customSAliasCommands = new Set(['config credentials'], ['config tabcompletion install']);
|
||||
|
||||
module.exports = memoizee(() => {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
const baseArgsSchema = {
|
||||
boolean: new Set(['help', 'help-interactive', 'v', 'version']),
|
||||
string: new Set(['app', 'config', 'org']),
|
||||
string: new Set(['app', 'config', 'org', 'stage']),
|
||||
alias: new Map([
|
||||
['c', 'config'],
|
||||
['h', 'help'],
|
||||
@ -29,6 +31,11 @@ module.exports = memoizee(() => {
|
||||
baseArgsSchema.boolean.delete('v');
|
||||
baseArgsSchema.alias.set('v', 'version');
|
||||
}
|
||||
if (!customSAliasCommands.has(command)) {
|
||||
// Unfortunately, there are few command for which "-s" aliases different param than "--stage"
|
||||
// This handling ensures we do not break those commands
|
||||
baseArgsSchema.alias.set('s', 'stage');
|
||||
}
|
||||
|
||||
options = parseArgs(args, baseArgsSchema);
|
||||
|
||||
|
||||
@ -63,6 +63,40 @@ describe('test/unit/lib/cli/resolve-input.test.js', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('"-s" handling', () => {
|
||||
describe('Normal command', () => {
|
||||
let data;
|
||||
before(() => {
|
||||
resolveInput.clear();
|
||||
data = overrideArgv(
|
||||
{
|
||||
args: ['serverless', 'cmd1', 'cmd2', '-s', 'stage'],
|
||||
},
|
||||
() => resolveInput()
|
||||
);
|
||||
});
|
||||
it('should recognize stage alias', async () => {
|
||||
expect(data.options.stage).to.equal('stage');
|
||||
});
|
||||
});
|
||||
describe('Command with custom -s alias', () => {
|
||||
let data;
|
||||
before(() => {
|
||||
resolveInput.clear();
|
||||
data = overrideArgv(
|
||||
{
|
||||
args: ['serverless', 'config', 'credentials', '-s', 'stage'],
|
||||
},
|
||||
() => resolveInput()
|
||||
);
|
||||
});
|
||||
it('should recognize stage alias', async () => {
|
||||
expect(data.options).to.not.have.property('stage');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when no commands', () => {
|
||||
let data;
|
||||
before(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user