0

我有以下设置

export const program = new Command();
program.version('0.0.1');

program
  .command('command-1')
  .description('command 1')
  .action(() => {
    executeCommand1Async()
      .then(() => {
        logger.info('Executed command 1');
      })
      .catch((e) => logger.error(e));
  });

program
  .command('command-2')
  .description('command 2')
  .action(() => {
    executeCommand2Async()
      .then(() => {
        logger.info('Executed command 2');
      })
      .catch((e) => logger.error(e));
  });

现在我还想让用户使用相同的命令同时执行 command-1 和 command-2,比如说root.

有没有办法做到这一点而不做

program
  .command('root')
  .description('Root command')
  .action(() => {
    try {
       await executeCommand1Async()
       logger.info('Executed command 1');

       await executeCommand2Async()
       logger.info('Executed command 2');
    } catch (e) {
       logger.error(e);
    }
  });
4

0 回答 0