-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
103 lines (93 loc) · 1.99 KB
/
commands.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
#!/usr/bin/env node
const commander = require('commander');
const { prompt } = require('inquirer');
const {
addEmployee,
findEmployee,
updateEmployee,
removeEmployee,
listEmployees
} = require('./index.js');
// Questions Prompt for addEmployee
const questions = [
{
type: 'input',
name: 'firstname',
message: 'Firstname: '
},
{
type: 'input',
name: 'lastname',
message: 'Lastname: '
},
{
type: 'input',
name: 'phone',
message: 'Phone: '
},
{
type: 'input',
name: 'email',
message: 'Email: '
},
{
type: 'input',
name: 'dept',
message: 'Department: '
},
{
type: 'input',
name: 'title',
message: 'Title: '
}
]
// Define version and description
commander
.version('1.0.0')
.description('Employee Management System')
// add command using commander.js
/* commander
.command('add <firstname> <lastname> <phone> <email> <dept> <title>')
.alias('a')
.description('Add Employee')
.action((firstname, lastname, phone, email, dept, title) => {
addEmployee({firstname, lastname, phone, email, dept, title});
});
*/
// Add command using questions prompt
commander
.command('add')
.alias('a')
.description('Add Employee Record')
.action(() => {
prompt(questions)
.then((answers) => addEmployee(answers));
});
// Define find command
commander
.command('find <name>')
.alias('f')
.description('Find Employee Record')
.action((name) => findEmployee(name));
// Update command
commander
.command('update <_id>')
.alias('u')
.description('Update Employee Record')
.action((_id) => {
prompt(questions)
.then((answers) => updateEmployee(_id, answers));
});
// Remove command
commander
.command('remove <name>')
.alias('r')
.description('Delete Employee Record')
.action((_id) => removeEmployee(_id));
// List command
commander
.command('list')
.alias('l')
.description('List all Employee Records')
.action(() => listEmployees());
commander.parse(process.argv);