Skip to content

Commit

Permalink
fix(CLI): Ensure command validation for service independent commands
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Oct 20, 2021
1 parent 006cec5 commit 6022fb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions scripts/serverless.js
Expand Up @@ -503,16 +503,17 @@ const processSpanPromise = (async () => {
// Validate result command and options
require('../lib/cli/ensure-supported-command')();
}
} else {
require('../lib/cli/ensure-supported-command')();
}

const configurationFilename = configuration && configurationPath.slice(serviceDir.length + 1);

const isStandaloneCommand = standaloneCommands.has(command);

if (isInteractiveSetup || isStandaloneCommand) {
if (configuration) require('../lib/cli/ensure-supported-command')(configuration);
if (isInteractiveSetup) {
require('../lib/cli/ensure-supported-command')(configuration);

if (!process.stdin.isTTY && !process.env.SLS_INTERACTIVE_SETUP_ENABLE) {
throw new ServerlessError(
'Attempted to run an interactive setup in non TTY environment.\n' +
Expand All @@ -531,7 +532,6 @@ const processSpanPromise = (async () => {
configuration = result.configuration;
}
} else {
require('../lib/cli/ensure-supported-command')(configuration);
await require(`../commands/${commands.join('-')}`)({
configuration,
serviceDir,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/scripts/serverless.test.js
Expand Up @@ -258,7 +258,7 @@ describe('test/unit/scripts/serverless.test.js', () => {
throw new Error('Unexpected');
} catch (error) {
expect(error.code).to.equal(1);
expect(String(error.stdoutBuffer)).to.include('command requires the');
expect(String(error.stdoutBuffer)).to.include('command "config credentials" requires');
}
});
});

0 comments on commit 6022fb9

Please sign in to comment.