-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (52 loc) · 1.37 KB
/
app.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
const program = require('commander')
const prompt = require('cli-input')
const notes = require('./lib/notes')
program
.command('add <title>')
.alias('a')
.description('add a new note')
.action(function (title) {
console.log('Type a note (finish with Ctrl^D): ')
var ps = prompt()
ps.multiline(function (err, lines, raw) {
if (err) {
console.log(err)
}
var note = notes.addNote(title, raw)
console.log(`New post created. Id: ${note.id}`)
process.exit(0)
})
})
program
.command('read <title>')
.alias('r')
.description('read a note')
.action(function (title) {
var note = notes.getNote(title)
console.log('--------------------')
console.log(`Title: ${note.title}`)
console.log('--------------------')
console.log(`Body: ${note.body}`)
console.log('--------------------')
})
program
.command('delete <title>')
.alias('d')
.description('delete a note')
.action(function (title) {
notes.removeNote(title)
})
program
.command('list')
.alias('l')
.description('list all notes')
.action(function () {
var notesArray = notes.getAll()
notesArray.forEach(function (note) {
console.log('--------------------')
console.log(`Title: ${note.title}`)
console.log('--------------------')
})
})
program.parse(process.argv)
if (!program.args.length) program.help()