diff --git a/.changeset/strange-dryers-eat.md b/.changeset/strange-dryers-eat.md new file mode 100644 index 0000000..7fa782c --- /dev/null +++ b/.changeset/strange-dryers-eat.md @@ -0,0 +1,5 @@ +--- +"@fleek-platform/cli": minor +--- + +Add common help command handler to prevent misses diff --git a/src/cli.ts b/src/cli.ts index c0eb3bc..fe692b3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -51,6 +51,9 @@ export const init = ({ version, parser }: InitArgs) => { .action(() => program.outputHelp()) .version(version); + // TODO: The ascii logo should only be displayed + // on default command, or general help + // a minimal version can be used instead program.addHelpText('beforeAll', logo).showHelpAfterError(); type CmdVersionArgs = typeof program; @@ -79,7 +82,17 @@ export const init = ({ version, parser }: InitArgs) => { ]; for (const cmd of commands) { - cmd(program); + const subCmd = cmd(program); + + // Attach common subcommands + if (subCmd) { + // TODO: Identify common subcommands + // refactor to handle them here + subCmd + .command('help') + .description(t('printHelp')) + .action(() => subCmd.help()); + } } // Init parser (unawaited) diff --git a/src/commands/applications/index.ts b/src/commands/applications/index.ts index 85cee8d..57be514 100644 --- a/src/commands/applications/index.ts +++ b/src/commands/applications/index.ts @@ -6,7 +6,7 @@ import { deleteApplicationActionHandler } from './delete'; import { listApplicationsActionHandler } from './list'; import { updateApplicationActionHandler } from './update'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('applications') .description(t('appCmdDescription')); @@ -61,4 +61,6 @@ export default (program: Command) => { deleteApplicationActionHandler(options), ) .addHelpCommand(); + + return cmd; }; diff --git a/src/commands/auth/index.ts b/src/commands/auth/index.ts index 11864d8..3d47d4a 100644 --- a/src/commands/auth/index.ts +++ b/src/commands/auth/index.ts @@ -6,7 +6,7 @@ import { t } from '../../utils/translation'; import { loginActionHandler } from './login'; import { logoutActionHandler } from './logout'; -export default (cmd: Command) => { +export default (cmd: Command): Command => { cmd .command('login') .description(t('cmdAuthLoginDescription')) @@ -30,4 +30,6 @@ export default (cmd: Command) => { .description(t('cmdAuthLogoutDescription')) .action(logoutActionHandler) .addHelpCommand(); + + return cmd; }; diff --git a/src/commands/domains/index.ts b/src/commands/domains/index.ts index 902e18f..3b6b793 100644 --- a/src/commands/domains/index.ts +++ b/src/commands/domains/index.ts @@ -7,7 +7,7 @@ import { detailDomainActionHandler } from './detail'; import { listDomainsActionHandler } from './list'; import { verifyDomainActionHandler } from './verify'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('domains') .option('-h, --help', t('printHelp')) @@ -83,5 +83,5 @@ export default (program: Command) => { ) .addHelpCommand(); - cmd.command('help').description(t('printHelp')); + return cmd; }; diff --git a/src/commands/ens/index.ts b/src/commands/ens/index.ts index 392b435..4688ca9 100644 --- a/src/commands/ens/index.ts +++ b/src/commands/ens/index.ts @@ -7,7 +7,7 @@ import { detailEnsRecordsActionHandler } from './detail'; import { listEnsRecordsActionHandler } from './list'; import { verifyEnsRecordActionHandler } from './verify'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('ens') .option('-h, --help', t('printHelp')) @@ -105,4 +105,6 @@ export default (program: Command) => { .addHelpCommand(); cmd.command('help').description(t('printHelp')); + + return cmd; }; diff --git a/src/commands/functions/index.ts b/src/commands/functions/index.ts index 59ce4cb..9dc9346 100644 --- a/src/commands/functions/index.ts +++ b/src/commands/functions/index.ts @@ -18,7 +18,7 @@ type DeployOptions = { sgx?: boolean; }; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('functions') .option('-h, --help', t('printHelp')) @@ -106,9 +106,5 @@ export default (program: Command) => { ) .addHelpCommand(); - cmd - .command('help') - .description(t('printHelp')) - .action(() => cmd.help()) - .addHelpCommand(); + return cmd; }; diff --git a/src/commands/gateways/index.ts b/src/commands/gateways/index.ts index 085436c..29ef649 100644 --- a/src/commands/gateways/index.ts +++ b/src/commands/gateways/index.ts @@ -6,7 +6,7 @@ import { deletePrivateGatewayActionHandler } from './delete'; import { detailPrivateGatewayActionHandler } from './detail'; import { listPrivateGatewaysActionHandler } from './list'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('gateways') .option('-h', '--help', t('printHelp')) @@ -73,5 +73,5 @@ export default (program: Command) => { ) .addHelpCommand(); - cmd.command('help').description(t('printHelp')); + return cmd; }; diff --git a/src/commands/ipfs/index.ts b/src/commands/ipfs/index.ts index d655d51..70f322a 100644 --- a/src/commands/ipfs/index.ts +++ b/src/commands/ipfs/index.ts @@ -3,7 +3,7 @@ import type { Command } from 'commander'; import { t } from '../../utils/translation'; import { addActionHandler } from './add'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('ipfs') .option('-h, --help', t('printHelp')) @@ -17,8 +17,5 @@ export default (program: Command) => { .action((path: string) => addActionHandler({ path })) .addHelpCommand(); - cmd - .command('help') - .description(t('printHelp')) - .action(() => program.help()); + return cmd; }; diff --git a/src/commands/ipns/index.ts b/src/commands/ipns/index.ts index 57cc51c..b8a8a82 100644 --- a/src/commands/ipns/index.ts +++ b/src/commands/ipns/index.ts @@ -7,7 +7,7 @@ import { listActionHandler } from './list'; import { publishActionHandler } from './publish'; import { resolveActionHandler } from './resolve'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('ipns') .option('-h, --help', 'Print help') @@ -73,8 +73,5 @@ export default (program: Command) => { .action((name: string) => resolveActionHandler({ name })) .addHelpCommand(); - cmd - .command('help') - .description(t('printHelp')) - .action(() => cmd.help()); + return cmd; }; diff --git a/src/commands/pat/index.ts b/src/commands/pat/index.ts index 6ed1a12..eec5e33 100644 --- a/src/commands/pat/index.ts +++ b/src/commands/pat/index.ts @@ -7,7 +7,7 @@ import { createPersonalAccessTokenActionHandler } from './create'; import { deletePersonalAccessTokenActionHandler } from './delete'; import { listPersonalAccessTokensActionHandler } from './list'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('pat') .option('-h, --help', t('printHelp')) @@ -55,5 +55,5 @@ export default (program: Command) => { ) .addHelpCommand(); - cmd.command('help').description(t('printHelp')); + return cmd; }; diff --git a/src/commands/projects/index.ts b/src/commands/projects/index.ts index 4d8cf64..3e698fd 100644 --- a/src/commands/projects/index.ts +++ b/src/commands/projects/index.ts @@ -5,7 +5,7 @@ import { createProjectActionHandler } from './create'; import { listProjectsActionHandler } from './list'; import { switchProjectActionHandler } from './switch'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('projects') .option('-h, --help', t('printHelp')) @@ -31,4 +31,6 @@ export default (program: Command) => { .description(t('projectsCreateNewDesc')) .action((options: { name: string }) => createProjectActionHandler(options)) .addHelpCommand(); + + return cmd; }; diff --git a/src/commands/sites/index.ts b/src/commands/sites/index.ts index 7ebb99a..0ca9f27 100644 --- a/src/commands/sites/index.ts +++ b/src/commands/sites/index.ts @@ -7,7 +7,7 @@ import { initActionHandler } from './init'; import { listActionHandler } from './list'; import { listDeploymentsActionHandler } from './listDeployments'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('sites') .option('-h, --help', t('printHelp')) @@ -63,8 +63,5 @@ export default (program: Command) => { ) .addHelpCommand(); - cmd - .command('help') - .description(t('printHelp')) - .action(() => cmd.help()); + return cmd; }; diff --git a/src/commands/storage/index.ts b/src/commands/storage/index.ts index fa993e7..681c37a 100644 --- a/src/commands/storage/index.ts +++ b/src/commands/storage/index.ts @@ -7,7 +7,7 @@ import { deleteStorageActionHandler } from './delete'; import { getStorageActionHandler } from './get'; import { listStorageActionHandler } from './list'; -export default (program: Command) => { +export default (program: Command): Command => { const cmd = program .command('storage') .description(t('storageCmdDescription')); @@ -80,4 +80,6 @@ export default (program: Command) => { .argument('', t('ipfsAddPathDescription')) .action((path: string) => addStorageActionHandler({ path })) .addHelpCommand(); + + return cmd; };