-
Notifications
You must be signed in to change notification settings - Fork 21
/
contact.js
executable file
·86 lines (73 loc) · 1.58 KB
/
contact.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
#!/usr/bin/env node
const program = require('commander');
const { prompt } = require('inquirer');
const {
addContact,
getContact,
addMultipleContacts,
getContactList,
updateContact,
deleteContact
} = require('./logic');
const questions = [
{
type : 'input',
name : 'firstname',
message : 'Enter firstname ..'
},
{
type : 'input',
name : 'lastname',
message : 'Enter lastname ..'
},
{
type : 'input',
name : 'phone',
message : 'Enter phone number ..'
},
{
type : 'input',
name : 'email',
message : 'Enter email address ..'
}
];
program
.version('0.0.1')
.description('Contact management system')
program
.command('addContact')
.alias('a')
.description('Add a contact')
.action(() => {
prompt(questions).then((answers) =>
addContact(answers));
});
program
.command('getContact <name>')
.alias('r')
.description('Get contact')
.action(name => getContact(name));
program
.command('updateContact <_id>')
.alias('u')
.description('Update contact')
.action(_id => {
prompt(questions).then((answers) =>
updateContact(_id, answers));
});
program
.command('deleteContact <_id>')
.alias('d')
.description('Delete contact')
.action(_id => deleteContact(_id));
program
.command('getContactList')
.alias('l')
.description('List contacts')
.action(() => getContactList());
// Assert that a VALID command is provided
if (!process.argv.slice(2).length || !/[arudl]/.test(process.argv.slice(2))) {
program.outputHelp();
process.exit();
}
program.parse(process.argv)