-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (33 loc) · 1.11 KB
/
index.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
const { program } = require('commander');
const contacts = require('./contacts');
const invokeAction = async ({ action, id, name, email, phone }) => {
switch (action) {
case 'listContacts':
const contactsList = await contacts.listContacts();
console.table(contactsList);
break;
case 'getContactById':
const contactById = await contacts.getContactById(id);
console.log(contactById);
break;
case 'addContact':
await contacts.addContact(name, email, String(phone));
break;
case 'removeContact':
await contacts.removeContact(id);
console.log('removed id:', id);
break;
default:
console.log('Enter valid command (listContacts, getContactById, addContact, removeContact)');
break;
}
}
program
.option('-a, --action, <type>')
.option('-i, --id, <type>')
.option('-n, --name, <type>')
.option('-e, --email, <type>')
.option('-p, --phone, <type>');
program.parse();
const options = program.opts();
invokeAction(options);