Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add consistent support for verb / noun swapping #7675

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/amplify-cli/src/input-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,41 @@ export function verifyInput(pluginPlatform: PluginPlatform, input: Input): Input
result.helpCommandAvailable = true;
}

// verify if `input.command` is an actual command.
if (commands && commands!.includes(input.command!)) {
result.verified = true;
break;
}

// verify if `input.command` is an alias for a command.
if (commandAliases && Object.keys(commandAliases).includes(input.command!)) {
input.command = commandAliases[input.command!];
result.verified = true;
break;
}

// if `input.command` is not a command name or an alias for a command, check the
// first sub-command for a verb / noun swap (i.e. `env add` versus `add env`).
if (commands && input.subCommands && commands!.includes(input.subCommands[0])) {
Bentheburrito marked this conversation as resolved.
Show resolved Hide resolved
const command = input.subCommands[0];
input.subCommands[0] = input.command!;
input.command = command;

result.verified = true;
break;
}

// same as above, but check if the first sub-command is an alias.
if (commandAliases && input.subCommands && Object.keys(commandAliases).includes(input.subCommands[0])) {
Bentheburrito marked this conversation as resolved.
Show resolved Hide resolved
const command = commandAliases[input.subCommands[0]];
input.subCommands[0] = input.command!;
input.command = command;

result.verified = true;
break;
}

// if `input.command` is the default plugin command, check `input.options` for what to do.
if (input.command! === constants.PLUGIN_DEFAULT_COMMAND) {
if (commands && commands!.includes(name)) {
input.command = name;
Expand Down