UNPKG

orgdo

Version:

Command-line tool to manage the Todo lists

140 lines (139 loc) 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Client_1 = require("../../Client"); const Clock_1 = require("../../Clock"); const _ = require("lodash"); const render = require("../../clock-render"); exports.command = "clock"; exports.describe = "Manage tomato clocks"; function builder(cmd) { return cmd .command({ command: "start [id]", describe: "Start clock", builder: (subcmd) => { return subcmd.positional("id", { describe: "Id of task", type: "number" }); }, handler: (options) => { Client_1.default.init().then(client => { new Clock_1.default(client) .start(options.id) .then(() => { Client_1.print(`Start clock.`); }) .catch(err => Client_1.printErrorAndExit(err)); }); } }) .command({ command: ["stop", "abort"], describe: "Stop clock", handler: (options) => { Client_1.default.init().then(client => { new Clock_1.default(client) .stop() .then(() => { Client_1.print(`Stop clock.`); }) .catch(err => Client_1.printErrorAndExit(err)); }); } }) .command({ command: "status", describe: "View current clock", handler: (options) => { Client_1.default.init().then(client => { new Clock_1.default(client) .status() .then(data => { if (data.state.type !== "idle") { Client_1.print(`Clock is ${data.state.type}, ${Clock_1.secondToTimeString(data.state.time)} remained`); } else { Client_1.print(`No running clock, done ${data.index} clocks today.`); } }) .catch(err => Client_1.printErrorAndExit(err)); }); } }) .command({ command: "set", describe: "Update clock settings", builder: (subcmd) => { return subcmd .option("work-time", { describe: "Work time of clock in minute", type: "number" }) .option("long-break-time", { describe: "Long break time of clock in minute", type: "number" }) .option("short-break-time", { describe: "Short break time of clock in minute", type: "number" }) .option("long-break-count", { describe: "How many clocks when take a long break", type: "number" }); }, handler: (options) => { Client_1.default.init().then(client => { new Clock_1.default(client) .update((_.pick(options, [ "long-break-time", "short-break-time", "long-break-count", "work-time" ]))) .then(settings => { Client_1.print(`long-break-time: ${settings["long-break-time"]} short-break-time: ${settings["short-break-time"]} long-break-count: ${settings["long-break-count"]} work-time: ${settings["work-time"]}`); }) .catch(err => Client_1.printErrorAndExit(err)); }); } }) .command({ command: ["list", "ls"], describe: "List clocks used everyday", builder: (subcmd) => { return subcmd .option("after", { describe: "List clock more recent than a specific date. yyyy-MM-dd", type: "string" }) .option("before", { describe: "List clock older than a specific date. yyyy-MM-dd", type: "string" }); }, handler: (options) => { Client_1.default.init().then(client => { new Clock_1.default(client) .list(options) .then(clocks => { if (clocks.length === 0) { Client_1.print("No clocks."); return; } const ret = render.renderClocks(new Date(options.after), new Date(options.before), clocks); Client_1.print(ret); }) .catch(err => Client_1.printErrorAndExit(err)); }); } }) .demandCommand(1, `Run 'orgdo clock <subcommand> --help' for more information on a command.`); } exports.builder = builder; function handler(argv) { } exports.handler = handler;