-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·49 lines (41 loc) · 1.01 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
const program = require("commander");
const api = require("./index");
const pkg = require("./package.json");
// option只是在写-h的时候做提示的作用
program.version(pkg.version);
program
.command("add <taskName>")
.description("add a task")
.action((...args) => {
let words = args.slice(0, -1).join(" ");
api
.add(words.replace(" [object Object]", ""))
.then(() => {
console.log("添加成功!");
})
.catch((e) => {
console.log("添加失败!", e);
});
});
program
.command("clear")
.description("clear all tasks")
.action(() => {
api
.clear()
.then(() => {
console.log("清除成功!");
})
.catch((e) => {
console.log("清除失败!", e);
});
});
program.parse(process.argv);
// 当用户只输入node cli.js时走到这里
if (process.argv.length === 2) {
api.showAll();
}
console.log("-----running");
// must be before .parse() since
// node's emit() is immediate