Skip to content

Commit

Permalink
feat: revamp help command (changing test names)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbez committed Jan 10, 2023
1 parent 0da3a8b commit 42455c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
26 changes: 13 additions & 13 deletions packages/amplify-cli-core/src/__tests__/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,47 +139,47 @@ describe('amplify help functions: ', () => {
},
];

it('test lookup command init not null', () => {
it('lookup valid command (init) and expect not null', () => {
let initCommandInfo = lookUpCommand(mockCommandsInfo, 'init');
expect(initCommandInfo).not.toBeUndefined();
});

it('test lookup command invalid is null', () => {
it('lookup invalid command and expect null', () => {
let invalidCommandInfo = lookUpCommand(mockCommandsInfo, 'invalidcommand');
expect(invalidCommandInfo).toBeUndefined();
});

it('test lookup command init correct command name', () => {
it('lookup valid command (init) and expect correct command name', () => {
let initCommandInfo = lookUpCommand(mockCommandsInfo, 'init');
expect(initCommandInfo!.command).toBe('init');
});

it('test lookup command configure correct command name', () => {
it('lookup valid command (configure) and expect correct command name', () => {
let initCommandInfo = lookUpCommand(mockCommandsInfo, 'configure');
expect(initCommandInfo!.command).toBe('configure');
});

it('test lookup subcommand configure project not null', () => {
it('lookup valid subcommand (configure project) and expect not null', () => {
let configureProjectSubCommandInfo = lookUpSubcommand(mockCommandsInfo, 'configure', 'project');
expect(configureProjectSubCommandInfo).not.toBeUndefined();
});

it('test lookup subcommand invalid is null', () => {
it('lookup invalid subcommand and expect null', () => {
let invalidSubCommandInfo = lookUpSubcommand(mockCommandsInfo, 'invalidcommand', 'invalidsubcommand');
expect(invalidSubCommandInfo).toBeUndefined();
});

it('test lookup subcommand configure project correct subcommand name', () => {
it('lookup valid subcommand (configure project) and expect correct subcommand name', () => {
let configureProjectSubCommandInfo = lookUpSubcommand(mockCommandsInfo, 'configure', 'project');
expect(configureProjectSubCommandInfo!.subCommand).toBe('project');
});

it('test lookup subcommand configure hosting correct subcommand name', () => {
it('lookup valid subcommand (configure hosting) correct subcommand name', () => {
let configureHostingSubCommandInfo = lookUpSubcommand(mockCommandsInfo, 'configure', 'hosting');
expect(configureHostingSubCommandInfo!.subCommand).toBe('hosting');
});

it('test parse configure from input', () => {
it('parse command (configure) from input', () => {
const configureInput = {
argv: ['node', 'amplify', 'configure', '-h'],
command: 'help',
Expand All @@ -192,7 +192,7 @@ describe('amplify help functions: ', () => {
expect(specifiedCommands.subCommand).toBe('');
});

it('test parse mock function from input', () => {
it('parse command and subcommand (mock function) from input', () => {
const mockFunctionInput = {
argv: ['node', 'amplify', 'mock', 'function', '-h'],
plugin: 'mock',
Expand All @@ -205,7 +205,7 @@ describe('amplify help functions: ', () => {
expect(specifiedCommands.subCommand).toBe('function');
});

it('test run help invalid command', () => {
it('run help invalid command', () => {
let mockContext: $TSContext;
mockContext = ({
input: {
Expand All @@ -221,7 +221,7 @@ describe('amplify help functions: ', () => {
expect(printer.info).toBeCalledWith(' ' + 'amplify <command> <subcommand> [flags]');
});

it('test run help mock', () => {
it('run help command (mock)', () => {
let mockContext: $TSContext;

mockContext = ({
Expand All @@ -240,7 +240,7 @@ describe('amplify help functions: ', () => {
expect(printer.info).toBeCalledWith(' ' + 'amplify mock <subcommand>');
});

it('test run help mock function', () => {
it('run help subcommand (mock function)', () => {
let mockContext: $TSContext;

mockContext = ({
Expand Down
16 changes: 10 additions & 6 deletions packages/amplify-cli/src/input-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ function preserveHelpInformation(input: Input): Input {
}

// prevent information in help option from being overwritten to true by saving it in subcommands
if (input.options && input.options[constants.HELP] && typeof input.options[constants.HELP] === "string") {
input.subCommands = input.subCommands ? [...input.subCommands, input.options[constants.HELP] as string] : [input.options[constants.HELP] as string];
} else if (input.options && input.options[constants.HELP_SHORT] && typeof input.options[constants.HELP_SHORT] === "string") {
input.subCommands = input.subCommands ? [...input.subCommands, input.options[constants.HELP_SHORT] as string] : [input.options[constants.HELP_SHORT] as string];
if (input.options && input.options[constants.HELP] && typeof input.options[constants.HELP] === 'string') {
input.subCommands = input.subCommands
? [...input.subCommands, input.options[constants.HELP] as string]
: [input.options[constants.HELP] as string];
} else if (input.options && input.options[constants.HELP_SHORT] && typeof input.options[constants.HELP_SHORT] === 'string') {
input.subCommands = input.subCommands
? [...input.subCommands, input.options[constants.HELP_SHORT] as string]
: [input.options[constants.HELP_SHORT] as string];
}

// preserve command information in plugin field
if (input.plugin && input.plugin !== "core") {
if (input.plugin && input.plugin !== 'core') {
if (input.subCommands && input.subCommands.length && input.argv.indexOf(input.plugin) > input.argv.indexOf(input.subCommands[0])) {
input.subCommands = [...input.subCommands, input.plugin];
} else {
Expand All @@ -96,7 +100,7 @@ function preserveHelpInformation(input: Input): Input {
function normalizeInput(input: Input): Input {
// -v --version => version command
// -h --help => help command
// -y --yes => yes option
// -y --yes => yes option
if (input.options) {
if (input.options[constants.VERSION] || input.options[constants.VERSION_SHORT]) {
input.options[constants.VERSION] = true;
Expand Down

0 comments on commit 42455c6

Please sign in to comment.