Skip to content

Commit 47600b5

Browse files
fix: gracefully fail if invalid option is passed to cli (#168)
* gracefully fail if invalid option is passed to cli * change throws to console.error in cli
1 parent 3df099f commit 47600b5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
import { createDB } from "./index";
3-
import { OPTION_TYPE_CHECKS } from "./constants";
3+
import { DEFAULT_OPTIONS_KEYS, OPTION_TYPE_CHECKS } from "./constants";
44
import { ServerOptions } from "../types";
55

66
async function main() {
@@ -9,11 +9,17 @@ async function main() {
99
_DO_NOT_USE_cli: true
1010
}
1111
for (const opt of definedOptions) {
12+
if (!DEFAULT_OPTIONS_KEYS.includes(opt)) {
13+
console.error(`Option ${opt} is not a valid option.`)
14+
return
15+
}
16+
1217
const index = process.argv.indexOf(opt)
1318
const optionValue = process.argv[index + 1]
1419

1520
if (optionValue === undefined) {
16-
throw `Option ${opt} must have a value.`
21+
console.error(`Option ${opt} must have a value.`)
22+
return
1723
}
1824

1925
const optionName = opt.slice(2)

0 commit comments

Comments
 (0)