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


TypeScript Command.usage方法代码示例

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


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


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