-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·72 lines (61 loc) · 1.73 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
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
import fs from 'fs'
import yargs from 'yargs'
import {RosterBuilder} from './src/rostering/RosterBuilder'
import {RosterFormatter} from './src/rostering/RosterFormatter'
const validateArgs = args => {
let errors = []
if (isNaN(args['start-date'])) {
errors.push('please provide valid start date')
}
if (isNaN(args['end-date'])) {
errors.push('please provide valid end date')
}
if (!fs.existsSync(args['filename'])) {
errors.push('input file does not exist')
}
if (args['start-date'] > args['end-date']) {
errors.push('please provide a valid date range')
}
if (errors.length > 0) {
console.log('\n' + errors.length + ' parameter errors found:')
console.log('===============================')
errors.forEach(function(error) {
console.log('- ' + error)
})
console.log('\n')
process.exit()
}
}
// Just an example. Tackle this however you like.
const getRosteredNurses = args => {
RosterBuilder.build({
filename: args['filename'],
startDate: args['start-date'],
endDate: args['end-date']
})
}
const outputFormattedRoster = roster =>
RosterFormatter.output(console.log, roster)
yargs
.usage('$0 <cmd> [args]')
.option('start-date', {
describe: 'the first date of the period to roster, in YYYY-MM-DD format'
})
.option('end-date', {
describe: 'the final date of the period to roster, in YYYY-MM-DD format'
})
.option('filename', {
describe: 'a nurses file to import'
})
.coerce(['start-date', 'end-date'], Date.parse)
.demandOption(['start-date', 'end-date', 'filename'])
.command(
'$0',
'Build a nurses roster',
() => {},
argv => {
validateArgs(argv)
outputFormattedRoster(getRosteredNurses(argv))
}
)
.help().argv