From 1003a582567a934b3635ff3542a345527f99dfd5 Mon Sep 17 00:00:00 2001 From: bn-l Date: Thu, 4 Apr 2024 21:21:09 +1100 Subject: [PATCH] unknown flag guard --- source/cli.mts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/cli.mts b/source/cli.mts index 96d4457..a952e75 100644 --- a/source/cli.mts +++ b/source/cli.mts @@ -32,6 +32,8 @@ export enum Option { conflictsOnly = "conflictsOnly", keepIf = "keepIf", quiet = "quiet", + help = "help", + version = "version", } export const helpText = ` @@ -110,11 +112,11 @@ export function getCli(argv?: string[]) { type: "string", choices: ["newer", "existing"], }, - help: { + [Option.help]: { type: "boolean", shortFlag: "h", }, - version: { + [Option.version]: { type: "boolean", shortFlag: "v", }, @@ -132,6 +134,13 @@ export function getCli(argv?: string[]) { ...(argv && { argv }), }); + for (const flag of Object.keys(cli.flags)) { + if (!(flag in Option)) { + console.error(`\nError: Uknown flag "${ flag }". Run ${ name } -h to show help.\n`); + process.exit(1); + } + } + if (cli.input.length === 0) { console.error(`\nError: Need at least one path. Run ${ name } -h to show help.\n`); process.exit(1);