當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Command.on方法代碼示例

本文整理匯總了TypeScript中commander.Command.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Command.on方法的具體用法?TypeScript Command.on怎麽用?TypeScript Command.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在commander.Command的用法示例。


在下文中一共展示了Command.on方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

    execute: async (programArgs:string[]) => {

      const program = new Command();

      // Callback for command success
      let onResolve:any;

      // Callback for command rejection
      let onReject:any = () => Promise.reject(Error("Uninitilized rejection throw"));

      // Command execution promise
      const currentCommand = new Promise((resolve, reject) => {
        onResolve = resolve;
        onReject = reject;
      });

      program
        .version(pjson.version)
        .usage('<command> [options]')

        .option('--home <path>', 'Path to Duniter HOME (defaults to "$HOME/.config/duniter").')
        .option('-d, --mdb <name>', 'Database name (defaults to "duniter_default").')

        .option('--autoconf', 'With `config` and `init` commands, will guess the best network and key options witout asking for confirmation')
        .option('--addep <endpoint>', 'With `config` command, add given endpoint to the list of endpoints of this node')
        .option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node')

        .option('--cpu <percent>', 'Percent of CPU usage for proof-of-work computation', parsePercent)

        .option('-c, --currency <name>', 'Name of the currency managed by this node.')

        .option('--nostdout', 'Disable stdout printing for `export-bc` command')
        .option('--noshuffle', 'Disable peers shuffling for `sync` command')

        .option('--timeout <milliseconds>', 'Timeout to use when contacting peers', parseInt)
        .option('--httplogs', 'Enable HTTP logs')
        .option('--nohttplogs', 'Disable HTTP logs')
        .option('--isolate', 'Avoid the node to send peering or status informations to the network')
        .option('--forksize <size>', 'Maximum size of fork window', parseInt)
        .option('--memory', 'Memory mode')
      ;

      for (const opt of options) {
        program
          .option(opt.optFormat, opt.optDesc, opt.optParser);
      }

      for (const cmd of commands) {
        program
          .command(cmd.command.name)
          .description(cmd.command.desc)
          .action(async function() {
            const args = Array.from(arguments);
            try {
              const resOfExecution = await cmd.executionCallback.apply(null, [program].concat(args));
              onResolve(resOfExecution);
            } catch (e) {
              onReject(e);
            }
          });
      }

      program
        .on('*', function (cmd:any) {
          console.log("Unknown command '%s'. Try --help for a listing of commands & options.", cmd);
          onResolve();
        });

      program.parse(programArgs);

      if (programArgs.length <= 2) {
        onReject('No command given.');
      }
      return currentCommand;
    }
開發者ID:Kalmac,項目名稱:duniter,代碼行數:75,代碼來源:cli.ts


注:本文中的commander.Command.on方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。