Skip to content

Commit 3fc254a

Browse files
committed
match via Array.prototype.includes
1 parent f57c4b7 commit 3fc254a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rescript

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,18 @@ process.on("SIGTERM", exitProcess);
6868
process.on("SIGHUP", exitProcess);
6969

7070
const args = process.argv.slice(2);
71-
const helpArgIndex = args.findIndex(arg => /help|-h|-help|--help/.test(arg));
71+
const argPatterns = {
72+
help: ['help', '-h', '-help', '--help'],
73+
version: ['version', '-v', '-version', '--version'],
74+
};
75+
76+
const helpArgIndex = args.findIndex(arg => argPatterns.help.includes(arg));
7277
const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-"));
7378

7479
if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)) {
7580
console.log(helpMessage);
7681

77-
} else if (/version|-v|-version|--version/.test(args[0])) {
82+
} else if (argPatterns.version.includes(args[0])) {
7883
console.log(require("./package.json").version);
7984

8085
} else if (firstPositionalArgIndex !== -1) {

0 commit comments

Comments
 (0)