Skip to content

Commit

Permalink
detect unused args
Browse files Browse the repository at this point in the history
  • Loading branch information
maddsua committed Sep 12, 2024
1 parent 8dea614 commit 0c8b246
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const getStringArg = (val: ArgTransformInput): string | null =>
export const parseArgs = (args: string[]): CliArgs => {

const result: Partial<CliArgs> = {};
const argSet = new Set(args.filter(item => item.startsWith('--')));

for (const key in argsProto) {

Expand All @@ -43,11 +44,17 @@ export const parseArgs = (args: string[]): CliArgs => {
continue;
}

argSet.delete(arg);

const valStartIdx = arg.indexOf('=');
const argValue = valStartIdx > 0 ? arg.slice(valStartIdx + 1): true;

result[key as keyof CliArgsProto] = argsProto[key as keyof CliArgsProto](argValue) as any;
}

if (argSet.size) {
throw new Error(`Unrecognized CLI arguments: ${Array.from(argSet.keys()).join('; ')}`);
}

return result as CliArgs;
};
2 changes: 1 addition & 1 deletion cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const main = async () => {
main().catch(error => {

const errorMessage = error instanceof Error ? `-> ${error.message}` : `Unhandled exception: ${error}`;
console.error(chalk.red(`❌ Asset processing terminated:\n`), errorMessage);
console.error(chalk.red(`❌ Operation canceled:\n`), errorMessage);

process.exit(1);
});
Expand Down

0 comments on commit 0c8b246

Please sign in to comment.