-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.js
65 lines (57 loc) · 1.11 KB
/
command.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const commander = require("commander");
const { prompt } = require("inquirer");
const { addTodo, deleteTodo, updateTodo, listTodos } = require("./index");
const question = [
{
type: "input",
name: "task",
message: "Enter Your Task"
},
{
type: "confirm",
name: "isCompleted",
message: "is task is completed"
}
];
commander
.command("add")
.description("add your task")
.alias("a")
.action(() => {
prompt(question)
.then(result => {
addTodo(result);
})
.catch(err => {
throw err;
});
});
commander
.command("update <task>")
.alias("u")
.description("update your todo ")
.action(task => {
prompt(question)
.then(result => {
updateTodo(task, result);
})
.catch(err => {
throw err;
});
});
commander
.command("list")
.alias("l")
.description("list all todos")
.action(() => {
listTodos();
});
commander
.command("delete <_id>")
.alias("d")
.description("delete todo by its id")
.action(_id => {
deleteTodo(_id);
});
commander.parse(process.argv);