-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (53 loc) · 1.43 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
const fs = require('fs')
const _ = require('lodash')
const yargs = require('yargs')
const notes = require('./notes.js')
var titleOptions = {
descibe: 'The note\'s title',
demand: true,
alias: 't'
}
var bodyOptions = {
descibe: 'The note\'s content',
demand: true,
alias: 'b'
}
const argv = yargs
.command('add', 'To add a new note', {
title: titleOptions,
body: bodyOptions
})
.command('list', 'To list all notes')
.command('read', 'To read a note', {
title: titleOptions
})
.command('remove', 'To remove a note by giving title', {
title: titleOptions
})
.help()
.argv
var command = process.argv[2]
// console.log(`Command : ${command}`)
if (command === 'add') {
var note = notes.addNote(argv.title, argv.body)
if (note == undefined) {
console.log('This note is already exist')
} else {
notes.logNote(note)
}
} else if (command === 'list') {
var noteList = notes.getAllNotes()
noteList.forEach(element => notes.logNote(element));
} else if (command === 'read') {
var note = notes.getNote(argv.title)
if (note === undefined) {
console.log('This note does not exist')
} else {
notes.logNote(note)
}
} else if (command === 'remove') {
var success = notes.removeNote(argv.title)
console.log(success ? 'Note was remove' : 'Note not exists')
} else {
console.log('Command not recognized')
}