Skip to content

Commit

Permalink
fix: enable help for category statuses (#12216)
Browse files Browse the repository at this point in the history
* fix: enable help for category statuses

* test: add e2e test for status with help
  • Loading branch information
goldbez authored and akshbhu committed Apr 18, 2023
1 parent f3c9a16 commit 73dc361
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 7 deletions.
66 changes: 60 additions & 6 deletions packages/amplify-cli-core/src/help/commands-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,71 @@ export const commandsInfo: Array<CommandInfo> = [
],
subCommands: [
{
subCommand: '[category]',
subCommandDescription: 'Shows the state of local resources not yet pushed to the cloud',
subCommandUsage: 'amplify status [category] [-v | --verbose]',
subCommand: 'notifications',
subCommandDescription: 'Lists the enabled/disabled statuses of the available notification channels',
subCommandUsage: 'amplify notifications status',
subCommandFlags: [],
},
{
subCommand: 'api',
subCommandDescription: 'Displays the current status of your API',
subCommandUsage: 'amplify api status [-acm <table-name>]',
subCommandFlags: [
{
short: 'v',
long: 'verbose',
flagDescription: 'Shows verbose details, including cloudformation differences',
short: 'acm',
long: '',
flagDescription: 'Displays the access control matrix',
},
],
},
{
subCommand: 'auth',
subCommandDescription: 'Displays the current status of your auth resource',
subCommandUsage: 'amplify auth status',
subCommandFlags: [],
},
{
subCommand: 'custom',
subCommandDescription: 'Displays the current status of your custom resource',
subCommandUsage: 'amplify custom status',
subCommandFlags: [],
},
{
subCommand: 'storage',
subCommandDescription: 'Displays the current status of your storage resource',
subCommandUsage: 'amplify storage status',
subCommandFlags: [],
},
{
subCommand: 'analytics',
subCommandDescription: 'Displays the current status of your analytics resource',
subCommandUsage: 'amplify analytics status',
subCommandFlags: [],
},
{
subCommand: 'function',
subCommandDescription: 'Displays the current status of your function resource',
subCommandUsage: 'amplify function status',
subCommandFlags: [],
},
{
subCommand: 'hosting',
subCommandDescription: 'Displays the current status of your hosting',
subCommandUsage: 'amplify hosting status',
subCommandFlags: [],
},
{
subCommand: 'interactions',
subCommandDescription: 'Displays the current status of your interactions resource',
subCommandUsage: 'amplify interactions status',
subCommandFlags: [],
},
{
subCommand: 'predictions',
subCommandDescription: 'Displays the current status of your predictions resource',
subCommandUsage: 'amplify predictions status',
subCommandFlags: [],
},
],
},
{
Expand Down
17 changes: 16 additions & 1 deletion packages/amplify-cli/src/input-manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// normalize command line arguments, allow verb / noun place switch
import { constants, PluginPlatform, pathManager, stateManager } from 'amplify-cli-core';
import { constants, PluginPlatform, pathManager, stateManager, commandsInfo } from 'amplify-cli-core';
import { getPluginsWithName, getAllPluginNames } from './plugin-manager';
import { InputVerificationResult } from './domain/input-verification-result';
import { insertAmplifyIgnore } from './extensions/amplify-helpers/git-manager';
Expand Down Expand Up @@ -84,6 +84,21 @@ function preserveHelpInformation(input: CLIInput): CLIInput {
subCommands.unshift(input.plugin);
}
}

if (input.command == 'status' && input.options) {
const statusSubcommands = commandsInfo
.find((commandInfo) => commandInfo.command == 'status')
?.subCommands.map((subCommandInfo) => subCommandInfo.subCommand);
const potentialStatusSubcommands: Array<string> = statusSubcommands ? statusSubcommands : [];
const optionKeys = Object.keys(input.options);
for (const potentialSubcommand of potentialStatusSubcommands) {
if (optionKeys.includes(potentialSubcommand)) {
subCommands.push(potentialSubcommand);
break;
}
}
}

if (input.options) {
input.options[constants.HELP] = true;
delete input.options[constants.HELP_SHORT];
Expand Down
17 changes: 17 additions & 0 deletions packages/amplify-e2e-core/src/utils/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getCLIPath, nspawn as spawn } from '..';

export const statusWithHelp = async (cwd: string, expectedContents: Array<string>): Promise<void> => {
const chain = spawn(getCLIPath(), ['status', '-h'], { cwd, stripColors: true });
for (const expectedLine of expectedContents) {
chain.wait(expectedLine);
}
await chain.runAsync();
};

export const statusForCategoryWithHelp = async (cwd: string, category: string, expectedContents: Array<string>): Promise<void> => {
const chain = spawn(getCLIPath(), ['status', category, '-h'], { cwd, stripColors: true });
for (const expectedLine of expectedContents) {
chain.wait(expectedLine);
}
await chain.runAsync();
};
1 change: 1 addition & 0 deletions packages/amplify-e2e-core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from './transformConfig';
export * from './admin-ui';
export * from './hooks';
export * from './git-operations';
export * from './help';

/**
* Whether the current environment is CircleCI or not
Expand Down
33 changes: 33 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/help.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
createNewProjectDir,
initJSProjectWithProfile,
deleteProject,
deleteProjectDir,
statusWithHelp,
statusForCategoryWithHelp,
addS3AndAuthWithAuthOnlyAccess,
amplifyPushAuth,
} from '@aws-amplify/amplify-e2e-core';

describe('help happy paths', () => {
let projRoot: string;
beforeAll(async () => {
projRoot = await createNewProjectDir('help-happy-paths');
await initJSProjectWithProfile(projRoot, {});
await addS3AndAuthWithAuthOnlyAccess(projRoot);
await amplifyPushAuth(projRoot);
});

afterAll(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

test('amplify status', async () => {
await statusWithHelp(projRoot, ['USAGE', 'amplify status [-v | --verbose]']);
});

test('amplify status storage', async () => {
await statusForCategoryWithHelp(projRoot, 'storage', ['USAGE', 'amplify storage status']);
});
});

0 comments on commit 73dc361

Please sign in to comment.