-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtasks.js
More file actions
60 lines (51 loc) · 1.15 KB
/
tasks.js
File metadata and controls
60 lines (51 loc) · 1.15 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
const fs = require('fs');
let tasks = ["Eat", "Sleep", "Play"];
let filename = 'ltcs.txt';
var command = process.argv[2];
function readTasks(){
}
fs.writeFile(filename, tasks, function(err){
if(err) console.log(err);
})
console.log("tasks were written to " + filename);
console.log("command", command);
function listTasks(){
if(tasks.length===0){
console.log("found no tasks");
}else{
console.log(`found ${tasks.length} lists`);
}
}
function clearTasks(){
fs.writeFile(filename, '', function(err){
if(err) console.log(err);
})
// tasks=[];
console.log(`Clear up the tasks ( ${tasks.length} )`);
}
function addTasks(){
let task = process.argv.slice(3).join(" ");
console.log('>task :', task);
tasks.push(task);
console.log(`Added the given tasks ( ${tasks.length} )`);
fs.writeFile(filename, tasks, function(err){
if(err) console.log(err);
})
console.log("tasks were written to " + filename);
}
function help(){
console.log("Type list, clear, or add");
}
switch(command){
case 'list':
listTasks();
break;
case 'clear':
clearTasks();
break;
case 'add':
addTasks();
break;
default:
help();
}