當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。