-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
31 lines (27 loc) · 767 Bytes
/
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
#!/usr/bin/env node
const program = require('commander');
const api = require('./index');
program
.option('-x, --xxx', 'output extra debugging')
program
.command('add')
.description('add a task')
.action((...args) => {
// console.log(args[args.length - 1])
let words = ''
if (args[args.length - 1].length) {
words = args[args.length - 1].join(' ')
}
api.add(words).then(() => { console.log('成功') }, () => { console.log('失败') })
});
program
.command('clear')
.description('clear a task')
.action(() => {
api.clear().then(() => { console.log('清除成功') }, () => { console.log('清除失败') })
});
program.parse(process.argv);
console.log(process.argv)
if (process.argv.length === 2) {
api.showAll()
}