Skip to content

Commit

Permalink
feat: revamp help command (#11667)
Browse files Browse the repository at this point in the history
* feat: revamp help command

* feat: revamp help command

* feat: revamp help command

* feat: revamp help command

* feat: revamp help command

* feat: revamp help command

* feat: revamp help command (resolving merge conflicts)

* feat: revamp help command (remove non-null assertions)

* feat: revamp help command (remove non-null assertions)

* feat: revamp help command (revisions)

* feat: revamp help command (revisions)

* feat: revamp help command (revisions)

* feat: revamp help command (update to use array find)

* feat: revamp help command (switch to single quotes)

* feat: revamp help command (switch to single quotes)

* feat: revamp help command (put imports on same line)

* feat: revamp help command (extract api)

* feat: revamp help command (prettier on help-helpers)

* feat: revamp help command (fix tag line)

* feat: revamp help command (changing test names)

* feat: revamp help command (refactoring preserveHelpInformation)
  • Loading branch information
goldbez committed Jan 10, 2023
1 parent 2831c9e commit 9977127
Show file tree
Hide file tree
Showing 28 changed files with 1,802 additions and 317 deletions.
32 changes: 4 additions & 28 deletions packages/amplify-category-analytics/src/commands/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $TSAny, $TSContext } from 'amplify-cli-core';
import { printer } from 'amplify-prompts';
import { run as runHelp } from './analytics/help';

export { run as analyticsPush } from './analytics/push';
export const name = 'analytics';
Expand All @@ -9,36 +9,12 @@ export const name = 'analytics';
* @param context amplify cli context
*/
export const run = async (context: $TSContext): Promise<$TSAny> => {
if (context.parameters.options.help) {
return runHelp(context);
}
if (/^win/.test(process.platform)) {
const { run: runCommand } = await import(`./${name}/${context.parameters.first}`);
return runCommand(context);
}
const header = `amplify ${name} <subcommand>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add an ${name} resource to your local backend`,
},
{
name: 'update',
description: `Takes you through steps in the CLI to update an ${name} resource`,
},
{
name: 'push',
description: `Provisions only ${name} cloud resources with the latest local developments`,
},
{
name: 'remove',
description: `Removes ${name} resource from your local backend. The resource is removed from the cloud on the next push command.`,
},
{
name: 'console',
description: `Opens the web console for the ${name} category`,
},
];

context.amplify.showHelp(header, commands);
printer.blankLine();
return context;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
37 changes: 5 additions & 32 deletions packages/amplify-category-auth/src/commands/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { $TSAny, $TSContext } from 'amplify-cli-core';
import { printer } from 'amplify-prompts';
import * as path from 'path';
import { run as runHelp } from './auth/help';

export const name = 'auth';

Expand All @@ -15,42 +16,14 @@ type AuthCommandType = {
* @returns auth command response
*/
export const run = async (context: $TSContext): Promise<$TSAny> => {
if (context.parameters.options.help) {
return runHelp(context);
}
try {
const { run: authRun } = await import(path.join('.', name, context.parameters.first));
return authRun(context);
} catch (err) {
const header = `amplify ${name} <subcommands>`;

const commands: AuthCommandType[] = [
{
name: 'add',
description: `Takes you through a CLI flow to add an ${name} resource to your local backend`,
},
{
name: 'import',
description: `Takes you through a CLI flow to import an existing ${name} resource to your local backend`,
},
{
name: 'push',
description: `Provisions only ${name} cloud resources with the latest local developments`,
},
{
name: 'remove',
description: `Removes the ${name} resource from your local backend which would be removed from the cloud on the next push command`,
},
{
name: 'update',
description: `Updates the ${name} resource from your local backend.`,
},
{
name: 'console',
description: `Opens the web console for the ${name} category`,
},
];

context.amplify.showHelp(header, commands);
printer.blankLine();
printer.error('Command not found');
}

return undefined;
};
5 changes: 5 additions & 0 deletions packages/amplify-category-auth/src/commands/auth/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
37 changes: 4 additions & 33 deletions packages/amplify-category-function/src/commands/function.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { categoryName } from '../constants';
import { run as runHelp } from './function/help';

module.exports = {
name: categoryName,
run: async context => {
if (context.parameters.options.help) {
return runHelp(context);
}
if (/^win/.test(process.platform)) {
try {
const { run } = require(`./${categoryName}/${context.parameters.first}`);
Expand All @@ -11,38 +15,5 @@ module.exports = {
context.print.error('Command not found');
}
}
const header = `amplify ${categoryName} <subcommands>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add a ${categoryName} resource to your local backend`,
},
{
name: 'update',
description: `Takes you through a CLI flow to update an existing ${categoryName} resource`,
},
{
name: 'push',
description: `Provisions only ${categoryName} cloud resources with the latest local developments`,
},
{
name: 'remove',
description: `Removes ${categoryName} resource from your local backend which would be removed from the cloud on the next push command`,
},
{
name: 'build',
description: 'Builds all the functions in the project (does an npm install on the functions src directory)',
},
{
name: 'console',
description: `Opens the web console for the ${categoryName} category`,
},
];

context.amplify.showHelp(header, commands);

context.print.info('');
return undefined;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
37 changes: 3 additions & 34 deletions packages/amplify-category-geo/src/commands/geo/help.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
import { $TSContext } from 'amplify-cli-core';
import { category } from '../../constants';
import { printer } from 'amplify-prompts';
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const name = category;

export const run = async (context: $TSContext) => {
const header = `amplify ${category} <subcommand>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add a ${category} resource to your local backend`,
},
{
name: 'update',
description: `Takes you through steps in the CLI to update a ${category} resource`,
},
{
name: 'push',
description: `Provisions only ${category} cloud resources with the latest local developments`,
},
{
name: 'remove',
description: `Removes ${category} resource from your local backend. The resource is removed from the cloud on the next push command.`,
},
{
name: 'console',
description: `Opens the web console for the ${category} category`,
},
];

context.amplify.showHelp(header, commands);

printer.blankLine();
export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import { run as runHelp } from './interactions/help';

const featureName = 'interactions';

module.exports = {
name: featureName,
run: async context => {
const header = `amplify ${featureName} <subcommand>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add an ${featureName} resource to your local backend`,
},
{
name: 'update',
description: `Takes you through a CLI flow to update an ${featureName} resource`,
},
{
name: 'push',
description: `Provisions only ${featureName} cloud resources with the latest local developments`,
},
{
name: 'remove',
description: `Removes ${featureName} resource from your local backend which would be removed from the cloud on the next push command`,
},
];

context.amplify.showHelp(header, commands);

context.print.info('');
if (context.parameters.options.help) {
return runHelp(context);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $TSAny, $TSContext } from 'amplify-cli-core';
import { printer } from 'amplify-prompts';
import { run as runHelp } from './notifications/help';

export const name = 'notifications';
export const alias = ['notification'];
Expand All @@ -10,6 +11,9 @@ export const alias = ['notification'];
* @returns Returns Notifications feature flow output in test/windows environment , and undefined otherwise
*/
export const run = async (context: $TSContext) : Promise<$TSAny|undefined> => {
if (context.parameters.options.help) {
return runHelp(context);
}
if (/^win/.test(process.platform)) {
try {
const notificationsFlow = await import(`./${name}/${context.parameters.first}`);
Expand All @@ -18,33 +22,5 @@ export const run = async (context: $TSContext) : Promise<$TSAny|undefined> => {
printer.error('Command not found');
}
}

const header = `amplify ${name} <subcommand>`;
const commands = [
{
name: 'add',
description: 'Adds a notification channel',
},
{
name: 'remove',
description: 'Removes a notification channel',
},
{
name: 'update',
description: 'Updates the configuration of a notification channel',
},
{
name: 'status',
description: 'Lists the enabled/disabled statuses of the available notification channels',
},
{
name: 'console',
description: 'Opens the Amazon Pinpoint console displaying the current channel settings',
},
];

context.amplify.showHelp(header, commands);
printer.blankLine();

return undefined;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};
28 changes: 5 additions & 23 deletions packages/amplify-category-predictions/src/commands/predictions.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import { run as runHelp } from './predictions/help';

const categoryName = 'predictions';

module.exports = {
name: categoryName,
alias: ['Predictions'],
run: async context => {
const header = `amplify ${categoryName} <subcommand>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add a ${categoryName} resource to your local backend`,
},
{
name: 'remove',
description: `Removes ${categoryName} resource from your local backend which would be removed from the cloud on the next push command`,
},
{
name: 'update',
description: `Takes you through steps in the CLI to update an ${categoryName} resource`,
},
{
name: 'console',
description: `Opens a web console to view your ${categoryName} resource`,
},
];

context.amplify.showHelp(header, commands);
context.print.info('');
if (context.parameters.options.help) {
return runHelp(context);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { $TSContext, runHelp, commandsInfo } from 'amplify-cli-core';

export const run = (context: $TSContext) => {
runHelp(context, commandsInfo);
};

0 comments on commit 9977127

Please sign in to comment.