serverless/lib/cli/resolve-input.js
Austen 158f644cd0
feat: Refactor logging to reduce complexity (#12432)
* chore: Change logger

* chore: continue refactor

* chore: WIP

* chore: Sync
2024-04-17 13:26:31 -07:00

38 lines
1.0 KiB
JavaScript

/**
* CLI params parser, to be used before we have deducted
* what commands and options are supported in given context.
*/
import commandsSchema from './commands-schema.js';
/**
* 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.
*/
export default (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;
};