Skip to content

Commit

Permalink
feat(bindgen): Add support for string and number arguments
Browse files Browse the repository at this point in the history
Fix bindgen script for handling InputTextStream and file inputs.
  • Loading branch information
jadh4v committed Oct 5, 2022
1 parent 3efaf52 commit 4220397
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int main(int argc, char * argv[])
bool charsetRequire{false};
pipeline.add_flag("--charset-require", charsetRequire, "require declaration of ext. charset (default)");
std::string charsetAssumeValue;
pipeline.add_option("--charset-assume", charsetAssumeValue, "[c]harset: string, assume charset c if no extended charset declared")->type_name("INPUT_TEXT_STREAM");
pipeline.add_option("--charset-assume", charsetAssumeValue, "[c]harset: string, assume charset c if no extended charset declared");
bool charsetCheckAll{false};
pipeline.add_flag("--charset-check-all", charsetCheckAll, "check all data elements with string values\n(default: only PN, LO, LT, SH, ST, UC and UT)");
#ifdef DCMTK_ENABLE_CHARSET_CONVERSION
Expand Down
19 changes: 15 additions & 4 deletions src/itk-wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ const interfaceJsonTypeToTypeScriptType = new Map([
['INPUT_POLYDATA', 'PolyData'],
['OUTPUT_POLYDATA', 'PolyData'],
['BOOL', 'boolean'],
['TEXT', 'string'],
['INT', 'number'],
])

const interfaceJsonTypeToInterfaceType = new Map([
Expand Down Expand Up @@ -351,6 +353,7 @@ function typescriptBindings(srcOutputDir, buildDir, wasmBinaries, forNode=false)
functionContent += ` ${interfaceType},\n`
})
functionContent += ` InterfaceTypes,\n`
functionContent += ` PipelineInput,\n`
if (forNode) {
functionContent += ` runPipelineNode\n`
} else {
Expand Down Expand Up @@ -404,7 +407,7 @@ function typescriptBindings(srcOutputDir, buildDir, wasmBinaries, forNode=false)
}
})
functionContent += ` ]\n`
functionContent += ` const inputs = [\n`
functionContent += ` const inputs: [ PipelineInput ] = [\n`
interfaceJson.inputs.forEach((input, index) => {
if (interfaceJsonTypeToInterfaceType.has(input.type)) {
const interfaceType = interfaceJsonTypeToInterfaceType.get(input.type)
Expand Down Expand Up @@ -458,9 +461,17 @@ function typescriptBindings(srcOutputDir, buildDir, wasmBinaries, forNode=false)
} else {
if (interfaceJsonTypeToInterfaceType.has(parameter.type)) {
const interfaceType = interfaceJsonTypeToInterfaceType.get(parameter.type)
const name = interfaceType.includes('File') ? `file${inputCount.toString()}` : inputCount.toString()
functionContent += ` args.push('--${parameter.name}', '${name}')\n`
inputCount++
if (interfaceType.includes('File')) {
// for files
functionContent += ` const inputFile = 'file' + inputs.length.toString()\n`
functionContent += ` inputs.push({ type: InterfaceTypes.${interfaceType}, data: { data: options.${camel}, path: inputFile } })\n`
functionContent += ` args.push('--${parameter.name}', inputFile)\n`
} else {
// for streams
functionContent += ` const inputCountString = inputs.length.toString()\n`
functionContent += ` inputs.push({ type: InterfaceTypes.${interfaceType}, data: { data: options.${camel} } })\n`
functionContent += ` args.push('--${parameter.name}', inputCountString)\n`
}
} else {
functionContent += ` args.push('--${parameter.name}', options.${camel}.toString())\n`
}
Expand Down

0 comments on commit 4220397

Please sign in to comment.