-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·89 lines (80 loc) · 1.86 KB
/
cli.js
File metadata and controls
executable file
·89 lines (80 loc) · 1.86 KB
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
#!/usr/bin/env node
import { hideBin } from "yargs/helpers";
import yargs from "yargs/yargs";
import { createNonDefaultCommand, executeCommand } from "./lib.js";
await yargs()
// Settings
.scriptName("pme")
.parserConfiguration({
"boolean-negation": false,
"dot-notation": false,
"duplicate-arguments-array": false,
"populate--": true,
"strip-aliased": true,
"strip-dashed": true,
// In preparation for yargs version 19, see:
// https://github.com/yargs/yargs-parser/pull/516
"greedy-arrays": true,
})
.showHelpOnFail(false)
.recommendCommands()
.strict()
// Usage
.usage("$0")
.usage("$0 [options]")
.usage("$0 <command> [options]")
// Commands
.command({
command: "$0",
describe: "Same as 'dev' command",
handler: executeCommand,
})
.command({
builder: createNonDefaultCommand,
command: "dev",
describe: "Watch data and template files and output PDF on change",
handler: executeCommand,
})
.command({
builder: createNonDefaultCommand,
command: "build",
describe: "Output PDF using data and template files",
handler: executeCommand,
})
// Options
.alias({ help: "h", version: "v" })
.options({
config: {
alias: "c",
describe: "Path to JavaScript config file",
type: "string",
},
data: {
alias: "d",
default: "data.yml",
describe: "Path to YAML data file",
type: "string",
},
output: {
alias: "o",
default: "output.pdf",
describe: "Path to PDF output file",
type: "string",
},
template: {
alias: "t",
default: "template.liquid",
describe: "Path to Liquid template file",
type: "string",
},
})
// Examples
.example([
["$0"],
["$0 -d info.yml"],
["$0 dev -t ./templates/default.liquid"],
["$0 build -o /home/user/document.pdf"],
["$0 -d info.yml -t ./templates/default.liquid -o /home/user/document.pdf"],
])
// Parse and execute
.parse(hideBin(process.argv));