Skip to content

Commit

Permalink
fix(cli): Build argument parser in awaitable function
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jun 10, 2024
1 parent ec36ec5 commit 5e3ca57
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions bids-validator/src/setup/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@ 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:https://bids.neuroimaging.io',
)
.arguments('<dataset_directory>')
.version(await getVersion())
.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',
)
async function getValidatorCommand() {
return 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:https://bids.neuroimaging.io',
)
.arguments('<dataset_directory>')
.version(await getVersion())
.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
Expand All @@ -49,7 +51,8 @@ export const validateCommand = new Command()
export async function parseOptions(
argumentOverride: string[] = Deno.args,
): Promise<ValidatorOptions> {
const { args, options } = await validateCommand.parse(argumentOverride)
const command = await getValidatorCommand()
const { args, options } = await command.parse(argumentOverride)
return {
datasetPath: args[0],
...options,
Expand Down

0 comments on commit 5e3ca57

Please sign in to comment.