Skip to content

Commit

Permalink
refactor: 💡 Common help command handler to prevent misses (#49)
Browse files Browse the repository at this point in the history
## Why?

Common help command handler to prevent misses

## How?

- The subcommand are now returned to main initialisation
- Attach command commands to subcommand
- Solve common `help` handler for all commands

## Tickets?

-
[PLAT-1665](https://linear.app/fleekxyz/issue/PLAT-1665/the-domains-help-subcommand-should-display-help)

## Contribution checklist?

- [x] The commit messages are detailed
- [x] The `build` command runs locally
- [ ] Assets or static content are linked and stored in the project
- [x] You have manually tested
- [ ] You have provided tests

## Security checklist?

- [ ] Sensitive data has been identified and is being protected properly
- [ ] Injection has been prevented (parameterized queries, no eval or
system calls)

## Preview?

<img width="807" alt="Screenshot 2024-10-28 at 12 28 20"
src="https://github.com/user-attachments/assets/2d2907dd-5b7d-4f9e-8220-3016f55a4c80">
  • Loading branch information
heldrida authored Oct 28, 2024
1 parent d4ed639 commit 12e1cd1
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-dryers-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleek-platform/cli": minor
---

Add common help command handler to prevent misses
15 changes: 14 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/commands/applications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -61,4 +61,6 @@ export default (program: Command) => {
deleteApplicationActionHandler(options),
)
.addHelpCommand();

return cmd;
};
4 changes: 3 additions & 1 deletion src/commands/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -30,4 +30,6 @@ export default (cmd: Command) => {
.description(t('cmdAuthLogoutDescription'))
.action(logoutActionHandler)
.addHelpCommand();

return cmd;
};
4 changes: 2 additions & 2 deletions src/commands/domains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -83,5 +83,5 @@ export default (program: Command) => {
)
.addHelpCommand();

cmd.command('help').description(t('printHelp'));
return cmd;
};
4 changes: 3 additions & 1 deletion src/commands/ens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -105,4 +105,6 @@ export default (program: Command) => {
.addHelpCommand();

cmd.command('help').description(t('printHelp'));

return cmd;
};
8 changes: 2 additions & 6 deletions src/commands/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -106,9 +106,5 @@ export default (program: Command) => {
)
.addHelpCommand();

cmd
.command('help')
.description(t('printHelp'))
.action(() => cmd.help())
.addHelpCommand();
return cmd;
};
4 changes: 2 additions & 2 deletions src/commands/gateways/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -73,5 +73,5 @@ export default (program: Command) => {
)
.addHelpCommand();

cmd.command('help').description(t('printHelp'));
return cmd;
};
7 changes: 2 additions & 5 deletions src/commands/ipfs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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;
};
7 changes: 2 additions & 5 deletions src/commands/ipns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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;
};
4 changes: 2 additions & 2 deletions src/commands/pat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -55,5 +55,5 @@ export default (program: Command) => {
)
.addHelpCommand();

cmd.command('help').description(t('printHelp'));
return cmd;
};
4 changes: 3 additions & 1 deletion src/commands/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -31,4 +31,6 @@ export default (program: Command) => {
.description(t('projectsCreateNewDesc'))
.action((options: { name: string }) => createProjectActionHandler(options))
.addHelpCommand();

return cmd;
};
7 changes: 2 additions & 5 deletions src/commands/sites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -63,8 +63,5 @@ export default (program: Command) => {
)
.addHelpCommand();

cmd
.command('help')
.description(t('printHelp'))
.action(() => cmd.help());
return cmd;
};
4 changes: 3 additions & 1 deletion src/commands/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -80,4 +80,6 @@ export default (program: Command) => {
.argument('<path>', t('ipfsAddPathDescription'))
.action((path: string) => addStorageActionHandler({ path }))
.addHelpCommand();

return cmd;
};

0 comments on commit 12e1cd1

Please sign in to comment.