From d61511d45dc545d2331dc56273bcc1dc07baace1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 8 Dec 2023 09:47:28 -0800 Subject: [PATCH 1/2] fix: cli parsing cases --- src/jco.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/jco.js b/src/jco.js index 377e91900..a441ed933 100755 --- a/src/jco.js +++ b/src/jco.js @@ -2,7 +2,7 @@ import { program, Option } from 'commander'; import { opt } from './cmd/opt.js'; import { transpile } from './cmd/transpile.js'; -import { run } from './cmd/run.js'; +import { run as runCmd } from './cmd/run.js'; import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js'; import { componentize } from './cmd/componentize.js'; import c from 'chalk-template'; @@ -55,12 +55,21 @@ program.command('run') .description('Run a WebAssembly Command component') .usage(' ') .helpOption(false) + .allowUnknownOption(true) + .allowExcessArguments(true) .argument('', 'Wasm command binary to run') .option('--jco-dir ', 'Instead of using a temporary dir, set the output directory for the run command') .option('--jco-trace', 'Enable call tracing') .option('--jco-import ', 'Custom module to import before the run executes to support custom environment setup') .argument('[args...]', 'Any CLI arguments to provide to the command') - .action(asyncAction(run)); + .action(asyncAction(async function run (cmd, args, opts, command) { + // specially only allow help option in first position + if (cmd === '--help' || cmd === '-h') { + command.help(); + } else { + return runCmd(cmd, args, opts); + } + })); program.command('opt') .description('optimizes a Wasm component, including running wasm-opt Binaryen optimizations') @@ -124,6 +133,8 @@ program.command('embed') .option('-m, --metadata ', 'field=name[@version] producer metadata to add with the embedding') .action(asyncAction(componentEmbed)); +program.showHelpAfterError(); + program.parse(); function asyncAction (cmd) { From a6ca8f197439aa3dfc158704b01bdcf57e30d2a7 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 8 Dec 2023 09:51:03 -0800 Subject: [PATCH 2/2] actually include parity cases --- src/cmd/transpile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/transpile.js b/src/cmd/transpile.js index 5a17047be..6d1892778 100644 --- a/src/cmd/transpile.js +++ b/src/cmd/transpile.js @@ -81,7 +81,7 @@ async function wasm2Js (source) { */ export async function transpileComponent (component, opts = {}) { await $init; - if (opts.noWasiShim || opts.instantiation) opts.wasiShim = false; + if (opts.instantiation) opts.wasiShim = false; let spinner; const showSpinner = getShowSpinner(); @@ -119,8 +119,8 @@ export async function transpileComponent (component, opts = {}) { instantiation, validLiftingOptimization: opts.validLiftingOptimization ?? false, tracing: opts.tracing ?? false, - noNodejsCompat: !(opts.nodejsCompat ?? true), - noTypescript: opts.noTypescript || false, + noNodejsCompat: opts.nodejsCompat === false, + noTypescript: opts.typescript === false, tlaCompat: opts.tlaCompat ?? false, base64Cutoff: opts.js ? 0 : opts.base64Cutoff ?? 5000, noNamespacedExports: opts.namespacedExports === false,