-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
cli.ts
executable file
·109 lines (98 loc) · 3.19 KB
/
cli.ts
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
104
105
106
107
108
109
#!/usr/bin/env node
import * as yargs from "yargs";
import { commitCommand } from "./commands/commit";
import { compileCommand } from "./commands/compile";
import { initCommand } from "./commands/init";
import { migrateCommand } from "./commands/migrate";
import { resetCommand } from "./commands/reset";
import { runCommand } from "./commands/run";
import { statusCommand } from "./commands/status";
import { uncommitCommand } from "./commands/uncommit";
import { watchCommand } from "./commands/watch";
import { isLoggedError } from "./lib";
import { version } from "./version";
function wrapHandler<T1, T2>(
input: yargs.CommandModule<T1, T2>,
): yargs.CommandModule<T1, T2> {
const { handler, ...rest } = input;
const newHandler: yargs.CommandModule<T1, T2>["handler"] = async (argv) => {
try {
return await Promise.resolve(handler(argv));
} catch (e) {
if (!isLoggedError(e)) {
// eslint-disable-next-line no-console
console.error(e);
}
process.exit(1);
}
};
return {
...rest,
handler: newHandler,
};
}
const f = yargs
.parserConfiguration({
"boolean-negation": true,
"camel-case-expansion": false,
"combine-arrays": false,
"dot-notation": false,
"duplicate-arguments-array": false,
"flatten-duplicate-arrays": false,
"halt-at-non-option": false,
"parse-numbers": false,
"populate--": false,
"set-placeholder-key": false,
"short-option-groups": true,
"sort-commands": false,
"strip-aliased": true,
"strip-dashed": false,
"unknown-options-as-args": false,
})
.scriptName("graphile-migrate")
.strict(true)
.version(version)
.hide("version")
.help(true)
.demandCommand(1, 1, "Please select a command to run.")
.recommendCommands()
// Commands
.command(wrapHandler(initCommand))
.command(wrapHandler(migrateCommand))
.command(wrapHandler(watchCommand))
.command(wrapHandler(commitCommand))
.command(wrapHandler(uncommitCommand))
.command(wrapHandler(statusCommand))
.command(wrapHandler(resetCommand))
.command(wrapHandler(compileCommand))
.command(wrapHandler(runCommand))
// Make sure options added here are represented in CommonArgv
.option("config", {
alias: "c",
type: "string",
description: "Optional path to gmrc file",
defaultDescription: ".gmrc[.js|.cjs]",
})
.completion("completion", "Generate shell completion script.")
.epilogue(
process.env.GRAPHILE_SPONSOR
? `\
You are running graphile-migrate v${version}.`
: `\
You are running graphile-migrate v${version}.
╔═══════════════════════════════════╗
║ Graphile Migrate is crowd-funded, ║
║ please consider sponsorship: ║
║ ║
║ https://www.graphile.org/sponsor/ ║
║ ║
║ 🙏 THANK YOU SPONSORS! 🙏 ║
╚═══════════════════════════════════╝
`,
).argv;
if ("then" in f && typeof f.then === "function") {
f.then(null, (e: Error) => {
// eslint-disable-next-line no-console
console.error(e);
});
}