-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
77 lines (67 loc) · 1.97 KB
/
app.js
File metadata and controls
77 lines (67 loc) · 1.97 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const chalk = require('chalk');
const yargs = require('yargs');
const { readNote } = require('./notes.js');
const notes = require('./notes.js');
// Customize yargs version
yargs.version("1.2.0");
//add
yargs.command({
command: "add",
describe: "adds a new note",
builder: { //builder property provides argument fascility for a command
title: {
describe: 'title of note',
demandOption: true, // this make sure that the argument is provided , by default this option is false.
type: 'string' //if dont mention this and if we pass the --title without any value it will store it as a boolean value
},
body: {
describe: 'body of note',
demandOption: true,
type: 'string'
}
},
handler: function (argv) { // handler function exicutes when ever the command is used
notes.addNotes(argv.title, argv.body);
}
});
//remove
yargs.command({
command: "remove",
describe: "removes a note.",
builder: {
title: {
describe: 'title of note to be removed',
demandOption: true,
type: 'string'
}
},
handler: function (argv) {
notes.removeNote(argv.title);
}
});
//list
yargs.command({
command: "list",
describe: "list all the note.",
handler: function () {
notes.listNotes();
}
});
//read
yargs.command({
command: "read",
describe: "read a selected note.",
builder: {
title: {
discribe: 'note title',
demandOption: true,
type: 'string'
}
},
handler: function (argv) {
readNote(argv.title);
}
});
yargs.argv; // this is necessary , by reading this value we are letting yargs to get to know that we need its parsing
// by removing the yargs wont work as expected
// some alternates may be yargs.parse();