-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (68 loc) · 1.72 KB
/
index.js
File metadata and controls
73 lines (68 loc) · 1.72 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
const yargs = require('yargs');
const chalk = require('chalk');
const contact = require('./contact');
//Add some contact
yargs.command({
command: 'add',
describe: `Input new contact example type: node . add --name="john" --email="john@gmail.com" --phone="08123123123" `,
builder: {
name: {
describe: 'Input fullname',
demandOption: true,
type: 'string'
},
email: {
describe: 'Input email',
demandOption: true,
type: 'string'
},
phone: {
describe: 'Input phone',
demandOption: true,
type: 'string'
}
},
handler(argv) {
contact.saveContact(argv.name, argv.email, argv.phone);
}
}).demandCommand();
//show all contact
yargs.command({
command: 'list',
describe: `Listing all contact, name, email nomor phone example type: node . list `,
handler() {
contact.listContact();
}
});
//Search contact by name
yargs.command({
command: 'search',
describe: `Search contact by name example type: node . search --name="john"`,
builder: {
name: {
describe: 'Input fullname',
demandOption: true,
type: 'string'
}
},
handler(argv) {
contact.detailContact(argv.name);
}
});
//Delete contact by email
yargs.command({
command: 'delete',
describe: `Delete contact by email example type: node . delete --email="john@gmail.com" `,
builder: {
email: {
describe: 'Input email',
demandOption: true,
type: 'string'
}
},
handler(argv) {
contact.deleteContact(argv.email);
}
});
//run yargs
yargs.parse();