From 8c7993d8665b013f42b7c742996537c976cb8051 Mon Sep 17 00:00:00 2001 From: Christian Emmer <10749361+emmercm@users.noreply.github.com> Date: Sun, 14 Jul 2024 17:32:08 -0400 Subject: [PATCH] Refactor: separate 'clean' help message options (#1215) --- src/modules/argumentsParser.ts | 28 ++++++++++++++++++---------- src/types/options.ts | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/modules/argumentsParser.ts b/src/modules/argumentsParser.ts index 02e66d3b8..b246d1bba 100644 --- a/src/modules/argumentsParser.ts +++ b/src/modules/argumentsParser.ts @@ -69,13 +69,14 @@ export default class ArgumentsParser { const groupDatInput = 'DAT input options:'; const groupPatchInput = 'Patch input options:'; const groupRomOutput = 'ROM output options (processed in order):'; - const groupRomZip = 'ROM zip command options:'; - const groupRomLink = 'ROM link command options:'; + const groupRomClean = 'clean command options:'; + const groupRomZip = 'zip command options:'; + const groupRomLink = 'link command options:'; const groupRomHeader = 'ROM header options:'; const groupRomSet = 'ROM set options:'; const groupRomFiltering = 'ROM filtering options:'; const groupRomPriority = 'One game, one ROM (1G1R) options:'; - const groupReport = 'Report options:'; + const groupReport = 'report command options:'; const groupHelpDebug = 'Help & debug options:'; // Add every command to a yargs object, recursively, resulting in the ability to specify @@ -410,15 +411,27 @@ export default class ArgumentsParser { description: 'Overwrite files in the output directory that are the wrong filesize, checksum, or zip contents', type: 'boolean', }) + .check((checkArgv) => { + if (checkArgv.help) { + return true; + } + const needOutput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command)); + if (!checkArgv.output && needOutput.length > 0) { + // TODO(cememr): print help message + throw new ExpectedError(`Missing required argument for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output `); + } + return true; + }) + .option('clean-exclude', { - group: groupRomOutput, + group: groupRomClean, alias: 'C', description: 'Path(s) to files to exclude from cleaning (supports globbing)', type: 'array', requiresArg: true, }) .option('clean-dry-run', { - group: groupRomOutput, + group: groupRomClean, description: 'Don\'t clean any files and instead only print what files would be cleaned', type: 'boolean', }) @@ -426,11 +439,6 @@ export default class ArgumentsParser { if (checkArgv.help) { return true; } - const needOutput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command)); - if (!checkArgv.output && needOutput.length > 0) { - // TODO(cememr): print help message - throw new ExpectedError(`Missing required argument for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output `); - } const needClean = ['clean-exclude', 'clean-dry-run'].filter((option) => checkArgv[option]); if (!checkArgv._.includes('clean') && needClean.length > 0) { // TODO(cememr): print help message diff --git a/src/types/options.ts b/src/types/options.ts index 8a9a2ac25..0cf812812 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -86,6 +86,7 @@ export interface OptionsProps { readonly dirGameSubdir?: string, readonly overwrite?: boolean, readonly overwriteInvalid?: boolean, + readonly cleanExclude?: string[], readonly cleanDryRun?: boolean,