serverless/lib/cli/resolve-input.js
2024-03-07 16:28:56 -08:00

35 lines
1.0 KiB
JavaScript

/**
* CLI params parser, to be used before we have deducted
* what commands and options are supported in given context.
*/
'use strict';
const commandsSchema = require('./commands-schema');
/**
* Parses command line arguments, identifies the command and
* its options, and returns an object containing these
* details. It also determines if the command is a
* container command or if a help request has been made,
* and sets corresponding flags in the returned object.
*/
module.exports = (providedCommandsSchema = commandsSchema, commands, options) => {
const command = commands.join(' ');
const commandSchema = providedCommandsSchema.get(command);
const result = { commands, options, command, commandSchema, commandsSchema: providedCommandsSchema };
if (!commandSchema) {
result.isContainerCommand = Array.from(providedCommandsSchema.keys()).some((commandName) =>
commandName.startsWith(`${command} `)
);
if (result.isContainerCommand) {
result.isHelpRequest = true;
return result;
}
}
return result;
};