UNPKG

todolists

Version:
88 lines (87 loc) 2.22 kB
#!/usr/bin/env node "use strict"; exports.__esModule = true; var fs = require("fs"); var path = require("path"); var program = require("commander"); var data_base_1 = require("./lib/data_base"); var cli_command_1 = require("./lib/cli_command"); var todo_list_1 = require("./lib/todo_list"); // instantiation the db var dataBase = new data_base_1["default"](); // read origin data var originData = dataBase.readData(); // instantiation todolist var todoList = new todo_list_1["default"](originData); // instantiation command var command = new cli_command_1["default"](todoList); var pkgConfig = { version: 'beta' }; try { pkgConfig = JSON.parse(fs.readFileSync(path.join(__dirname, './package.json'), 'utf-8')); } catch (e) { console.error(e); } program.version(pkgConfig.version).usage('. Make your own todolist in cli .'); // set default command if (!process.argv.slice(2).length) { command.listPending(); } // cli add todo item program .command('add <content>') .alias('a') .description('Add new todo item to list') .action(function (content, cmd) { content = process.argv.slice(3).join(' '); command.add(content); }); // remove todo item program .command('remove [id]') .alias('r') .description('Remove todo item') .option('-a --all', 'Clear all todo items') .action(function (id, options) { if (options.all) { command.removeAll(); return; } id = parseInt(id); command.remove(id); }); // list todolist program .command('ls') .description('List all todolist include checked item') .action(function (cli, options) { command.listAll(); }); // check todo item program .command('check <id>') .alias('c') .description('Check todo item as completed') .action(function (id) { id = parseInt(id); command.check(id); }); // uncheck todo item program .command('uncheck <id>') .alias('uc') .description('Uncheck todo item as pending') .action(function (id) { id = parseInt(id); command.uncheck(id); }); // resort todo list program .command('resort') .description('Resort todo list id') .action(function () { command.resort(); }); program.parse(process.argv);