UNPKG

orgdo

Version:

Command-line tool to manage the Todo lists

122 lines (121 loc) 4.58 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const Task_1 = require("./Task"); const taskFilters = require("./task-filters"); class Cli { constructor(client) { this.client = client; } list(options) { return __awaiter(this, void 0, void 0, function* () { const filters = []; if (options.tags) { filters.push(task => { if (task.tags.length === 0) { return false; } return taskFilters.newTagsFilter(options.tags)(task.tags); }); } if (options.priority) { filters.push(task => taskFilters.newEqualAnyFilter(options.priority)(task.priority)); } if (options.status) { filters.push(task => taskFilters.newEqualAnyFilter(options.status)(task.status)); } ["start", "started", "complete", "completed"].map(key => { if (options[key]) { filters.push(task => { if (!task[key]) { return /ed$/.test(key) ? false : true; } return taskFilters.newTimerFilter(options[key])(task[key]); }); } }); if (options.name) { filters.push(task => taskFilters.newRegexpFilter(options.name)(task.name)); } const filter = taskFilters.combine(filters); return this.client.listTasks(filter); }); } add(options) { return __awaiter(this, void 0, void 0, function* () { const { tags, describe, priority, start, complete, name } = options; const id = yield this.client.incId("taskId"); const task = Task_1.default.create({ id, tags, describe, priority, start, complete, name }); yield this.client.addTask(task); return task; }); } update(options) { return __awaiter(this, void 0, void 0, function* () { const task = yield this.client.getTask(options.id); task.update(options); if (options["add-tags"]) { task.addTags(options["add-tags"]); } if (options["remove-tags"]) { task.removeTags(options["remove-tags"]); } yield this.client.updateTask(task); return task; }); } cancel(options) { return __awaiter(this, void 0, void 0, function* () { const task = yield this.client.getTask(options.id); task.updateStatus("canceled"); task.completed = new Date(); yield this.client.updateTask(task); return task; }); } done(options) { return __awaiter(this, void 0, void 0, function* () { const task = yield this.client.getTask(options.id); task.updateStatus("done"); task.completed = new Date(); yield this.client.updateTask(task); return task; }); } get(options) { return __awaiter(this, void 0, void 0, function* () { const task = yield this.client.getTask(options.id); return task; }); } start(options) { return __awaiter(this, void 0, void 0, function* () { const task = yield this.client.getTask(options.id); task.updateStatus("doing"); task.started = new Date(); yield this.client.updateTask(task); return task; }); } remove(options) { return __awaiter(this, void 0, void 0, function* () { yield this.client.removeTask(options.id); }); } } exports.default = Cli;