/
arguments.js
33 lines (31 loc) · 1011 Bytes
/
arguments.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
const moment = require("moment");
const argv = require('yargs')
.usage("Usage: $0 [options]")
.alias("d", "directory")
.nargs("d", 1)
.describe("d", "Parent directory")
.alias("a", "author")
.nargs("a", 1)
.describe("a", "Author email address")
.alias("s", "start-date")
.nargs("s", 1)
.string("s")
.describe("s", "Start date")
.coerce("s", arg => {
if (Array.isArray(arg)) throw new Error("Only one occurrence allowed: start date");
const momentDate = moment(arg, "YYYY-MM-DD");
return momentDate.isValid() ? momentDate : null;
})
.alias("e", "end-date")
.nargs("e", 1)
.string("e")
.describe("e", "End date")
.coerce("e", arg => {
if (Array.isArray(arg)) throw new Error("Only one occurrence allowed: end date");
const momentDate = moment(arg, "YYYY-MM-DD");
return momentDate.isValid() ? momentDate : null;
})
.help("h")
.alias("h", "help")
.argv;
module.exports = argv;