-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (69 loc) · 2.51 KB
/
index.js
File metadata and controls
85 lines (69 loc) · 2.51 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
import showHelp from './scripts/help.js';
import * as crudList from './scripts/crudList.js';
const args = process.argv.slice(2);
function main() {
if (args.length === 0 || args[0] === 'help') {
console.log(showHelp());
return;
}
const command = args[0].toLowerCase();
switch (command) {
case 'add':
if (args.length < 2) {
console.error('Error: Please provide a task description');
process.exit(1);
}
var description = args.slice(1).join(' ');
console.log(`Adding task with id: "${crudList.addTask(description)}"`);
break;
case 'update':
if (args.length < 3) {
console.error('Error: Please provide task ID and new description');
process.exit(1);
}
var id = args[1];
var newDesc = args.slice(2).join(' ');
console.log(`Updating task ${id}: "${crudList.updateTask(id, newDesc)}"`);
break;
case 'delete':
if (args.length < 2) {
console.error('Error: Please provide a task ID');
process.exit(1);
}
var id = args[1];
console.log(`Deleting task was: "${crudList.deleteTask(id)}"`);
break;
case 'mark-in-progress':
if (args.length < 2) {
console.error('Error: Please provide a task ID');
process.exit(1);
}
console.log(`Marking task ${crudList.updateTaskStatus(args[1], "in-progress")} as in progress`);
// TODO: Implement mark in progress functionality
break;
case 'mark-done':
if (args.length < 2) {
console.error('Error: Please provide a task ID');
process.exit(1);
}
console.log(`Marking task ${crudList.updateTaskStatus(args[1], "done")} as done`);
break;
case 'list':
if (args.length < 2) {
console.log(crudList.listAll());
}else{
console.log(crudList.filteredList(args[1]));
}
break;
case 'reset':
console.log('Resetting all tasks...');
crudList.reset();
break;
default:
console.error(`Error: Unknown command "${command}"`);
console.log('Run "tracker help" for usage information');
process.exit(1);
}
}
main();