Skip to content

Commit

Permalink
Merge pull request #1844 from nellh/feat/composable-command-export
Browse files Browse the repository at this point in the history
feat: Add an export for validateCommand to allow other tools to reuse the validator's argument parsing
  • Loading branch information
rwblair authored Nov 13, 2023
2 parents 1b80645 + 20c36b1 commit 580a07e
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions bids-validator/src/setup/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,43 @@ 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 https://bids.neuroimaging.io',
)
.arguments('<dataset_directory>')
.version('alpha')
.option('--json', 'Output machine readable JSON')
.option(
'-s, --schema <type:string>',
'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 <type:debugLevel>', '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
*/
export async function parseOptions(
argumentOverride: string[] = Deno.args,
): Promise<ValidatorOptions> {
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 https://bids.neuroimaging.io',
)
.arguments('<dataset_directory>')
.version('alpha')
.option('--json', 'Output machine readable JSON')
.option(
'-s, --schema <type:string>',
'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 <type:debugLevel>', '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,
Expand Down

0 comments on commit 580a07e

Please sign in to comment.