Skip to content

Commit

Permalink
unknown flag guard
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-l committed Apr 4, 2024
1 parent d66724a commit 1003a58
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export enum Option {
conflictsOnly = "conflictsOnly",
keepIf = "keepIf",
quiet = "quiet",
help = "help",
version = "version",
}

export const helpText = `
Expand Down Expand Up @@ -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",
},
Expand All @@ -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);
Expand Down

0 comments on commit 1003a58

Please sign in to comment.