From 20c36b14ac1ef8ebd4f1050f1bf294e1fc4ff329 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Sun, 12 Nov 2023 16:41:31 -0800 Subject: [PATCH] feat: Add an export for validateCommand to allow other tools to reuse the validator's argument parsing --- bids-validator/src/setup/options.ts | 59 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/bids-validator/src/setup/options.ts b/bids-validator/src/setup/options.ts index 79374c954..7e7c9e084 100644 --- a/bids-validator/src/setup/options.ts +++ b/bids-validator/src/setup/options.ts @@ -12,6 +12,35 @@ export type ValidatorOptions = { debug: LevelName } +export const validateCommand = new Command() + .name('bids-validator') + .type('debugLevel', new EnumType(LogLevelNames)) + .description( + 'This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about Brain Imaging Data Structure visit http://bids.neuroimaging.io', + ) + .arguments('') + .version('alpha') + .option('--json', 'Output machine readable JSON') + .option( + '-s, --schema ', + 'Specify a schema version to use for validation', + { + default: 'latest', + }, + ) + .option('-v, --verbose', 'Log more extensive information about issues') + .option( + '--ignoreNiftiHeaders', + 'Disregard NIfTI header content during validation', + ) + .option('--debug ', 'Enable debug output', { + default: 'ERROR', + }) + .option( + '--filenameMode', + 'Enable filename checks for newline separated filenames read from stdin', + ) + /** * Parse command line options and return a ValidatorOptions config * @param argumentOverride Override the arguments instead of using Deno.args @@ -19,35 +48,7 @@ export type ValidatorOptions = { export async function parseOptions( argumentOverride: string[] = Deno.args, ): Promise { - const { args, options } = await new Command() - .name('bids-validator') - .type('debugLevel', new EnumType(LogLevelNames)) - .description( - 'This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about Brain Imaging Data Structure visit http://bids.neuroimaging.io', - ) - .arguments('') - .version('alpha') - .option('--json', 'Output machine readable JSON') - .option( - '-s, --schema ', - 'Specify a schema version to use for validation', - { - default: 'latest', - }, - ) - .option('-v, --verbose', 'Log more extensive information about issues') - .option( - '--ignoreNiftiHeaders', - 'Disregard NIfTI header content during validation', - ) - .option('--debug ', 'Enable debug output', { - default: 'ERROR', - }) - .option( - '--filenameMode', - 'Enable filename checks for newline separated filenames read from stdin', - ) - .parse(argumentOverride) + const { args, options } = await validateCommand.parse(argumentOverride) return { datasetPath: args[0], ...options,