forked from mate-academy/git-playground-task4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.js
More file actions
61 lines (58 loc) · 1.63 KB
/
Copy pathnotes.js
File metadata and controls
61 lines (58 loc) · 1.63 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
#!/usr/bin/env node
const store = require("./lib/store");
const config = require("./lib/config");
const [command, ...rest] = process.argv.slice(2);
function main() {
switch (command) {
case "add": {
const text = rest.join(" ").trim();
if (!text) {
console.log("Usage: notes add <your note>");
return;
}
const note = store.add(text);
console.log(`Added note #${note.id}: ${note.text}`);
break;
}
case "list": {
const notes = store.all();
if (notes.length === 0) {
console.log("No notes yet. Add one with: notes add <text>");
return;
}
for (const note of notes) {
console.log(`#${note.id} ${note.text}`);
}
break;
}
case "search": {
const term = rest.join(" ").trim();
const found = store.search(term);
if (found.length === 0) {
console.log(`No notes match "${term}"`);
return;
}
for (const note of found) {
console.log(`#${note.id} ${note.text}`);
}
break;
}
case "edit": {
const id = Number(rest[0]);
const text = rest.slice(1).join(" ").trim();
store.edit(id, text);
console.log(`Updated note #${id}`);
break;
}
case "delete": {
const id = Number(rest[0]);
const ok = store.remove(id);
console.log(ok ? `Deleted note #${id}` : `No note #${id} found`);
break;
}
default:
console.log("Commands: add <text> | list | search <term> | edit <id> <text> | delete <id>");
console.log(`(Session locks after ${config.SESSION_TIMEOUT_MINUTES} minutes of inactivity.)`);
}
}
main();