-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
118 lines (87 loc) · 2.52 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//console.log('Starting app.js');
//predefined modules
const fs = require('fs');
const _ = require('lodash')
//yargs makes passing keyvalue pairs as command line arguments easier
const yargs = require('yargs');
//internal dependency files
const notes = require('./notes.js')
const titleOptions = {
describe : 'Title of note',
demand : true,
alias : 't'
};
const bodyOptions = {
describe : 'Body of note',
demand : true,
alias : 'b'
};
const argv = yargs
.command('add', 'Add a new note', {
title: titleOptions,
body: bodyOptions
})
.command('list', 'List all notes')
.command('read', 'Read a note', {
title: titleOptions,
})
.command('remove', 'Remove a note', {
title: titleOptions
})
.help()
.argv;
var command = argv._[0];
//console.log('\nYargs:', arg);
//var command = process.argv[2];
//console.log('Command:', command);
//console.log('\nProcess:', process.argv);
if (command === 'add') {
//console.log('Adding new note');
var noteAdded = notes.addNote(argv.title, argv.body);
if(noteAdded){
console.log("\nSuccessfully added new note in database!");
notes.logNote(noteAdded);
}
else
console.log("\nNote with same title already exists");
} else if (command === 'list') {
//console.log('Listing all notes');
var allNotes = notes.getAllNotes();
console.log(`Printing ${allNotes.length} note(s).`);
allNotes.forEach((note) => notes.logNote(note));
} else if (command === 'read') {
//console.log('Reading note');
var note = notes.getNote(argv.title);
if(note){
console.log("\nNote with title: "+ argv.title + " found!");
notes.logNote(note);
}
else{
console.log('Note not found!');
}
} else if (command === 'remove') {
//console.log('Removing note');
var noteRemoved = notes.removeNote(argv.title);
var message = noteRemoved ? "Note Removed!" : "Note not found!";
console.log(message);
} else {
console.log('Command not recognised');
}
/*
console.log(_.isString(true));
console.log(_.isString('Chirag'));
var filteredArray = _.uniq(['Shah', 1, 'Chirag', 1, 2, 3, 4]);
console.log(filteredArray);
var res = notes.addNote();
console.log(res);
var res = notes.addFunction(4, 5);
console.log('Result:' + res);
const os = require('os');
var user = os.userInfo();
//remember the ` symbol while using es6 feature
fs.appendFile('greetings.txt', `Hello ${user.username}!`, function(err) {
if (err) {
console.log(err);
}
});
*/