当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Command.parse方法代码示例

本文整理汇总了TypeScript中commander.Command.parse方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Command.parse方法的具体用法?TypeScript Command.parse怎么用?TypeScript Command.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在commander.Command的用法示例。


在下文中一共展示了Command.parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: main

async function main() {
  // Command-line interface.
  let program = new commander.Command();
  let filename: string | undefined = undefined;
  program
    .usage('[options] <calendar.ics>')
    .option('-a, --agenda', 'print human-readable agenda')
    .option('-g, --grid', 'print availability grid')
    .option('-d, --date <date>', 'show data for a given day')
    .option('-w, --week <date>', 'show data for a given week')
    .action((fn) => {
      filename = fn;
    });
  program.parse(process.argv);

  if (!filename) {
    program.help();
    return;
  }
  let opts = program.opts();

  // Parse the calendar.
  let data = await read_string(filename);
  let jcal = ICAL.parse(data);

  // Time range.
  let day: ICAL.Time;
  let start: ICAL.Time;
  let end: ICAL.Time;
  if (opts.date) {
    // Show a single day.
    day = ICAL.Time.fromString(opts.date);
    start = end = day;
  } else {
    // Show a whole week (the default).
    if (opts.week) {
      day = ICAL.Time.fromString(opts.week);
    } else {
      day = ICAL.Time.now();
    }
    start = day.startOfWeek();
    end = day.endOfWeek();
    end.adjust(1, 0, 0, 0);  // "One past the end" for iteration.
  }

  // Get events in the range.
  let instances = Array.from(get_occurrences(jcal, start, end));

  // Display the data.
  let dates_iter = iter_time(start, end, new ICAL.Duration({ days: 1 }));
  if (opts.agenda) {
    // Agenda display.
    for (let date of dates_iter) {
      for (let line of show_agenda(instances, date)) {
        console.log(line);
      }
    }
  } else {
    // Grid display.
    console.log(draw_header());
    for (let date of dates_iter) {
      for (let line of draw_avail(instances, date)) {
        console.log(line);
      }
    }
  }

}
开发者ID:sampsyo,项目名称:calcat,代码行数:68,代码来源:calcat.ts

示例2: 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

示例3:

  .description('bootstrap project')
  .action(bootstrap);

program
  .command('configure')
  .description('configure project')
  .action(configure);

program
  .command('backup [destination]')
  .option('--firestore', 'backup Firestore')
  .option('--storage', 'backup storage')
  .option('--accounts', 'backup accounts')
  .description('backup project data')
  .action(backup);

program
  .command('restore [source]')
  .option('--firestore', 'restore Firestore')
  .option('--storage', 'restore storage')
  .option('--accounts', 'restore accounts')
  .description('restore backup folder to project')
  .action(restore);

program
  .command('upload')
  .description('upload file or directory content')
  .action(upload);

program.parse(process.argv);
开发者ID:accosine,项目名称:poltergeist,代码行数:30,代码来源:cli.ts


注:本文中的commander.Command.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。