forked from graphile/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
executable file
·98 lines (89 loc) · 2.88 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
#!/usr/bin/env node
import * as yargs from "yargs";
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
import { version } from "../package.json";
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";
function wrapHandler(
input: yargs.CommandModule<unknown, unknown>,
): yargs.CommandModule<unknown, unknown> {
const { handler, ...rest } = input;
const newHandler: yargs.CommandModule<
unknown,
unknown
>["handler"] = async argv => {
try {
return await Promise.resolve(handler(argv));
} catch (e) {
if (!e["_gmlogged"]) {
// eslint-disable-next-line no-console
console.error(e);
}
process.exit(1);
}
};
return {
...rest,
handler: newHandler,
};
}
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))
.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;