Skip to content

Commit

Permalink
fix: cli parsing cases (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Dec 8, 2023
1 parent ed6c88b commit d32d2ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/cmd/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/jco.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -55,12 +55,21 @@ program.command('run')
.description('Run a WebAssembly Command component')
.usage('<command.wasm> <args...>')
.helpOption(false)
.allowUnknownOption(true)
.allowExcessArguments(true)
.argument('<command>', 'Wasm command binary to run')
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the run command')
.option('--jco-trace', 'Enable call tracing')
.option('--jco-import <module>', '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')
Expand Down Expand Up @@ -124,6 +133,8 @@ program.command('embed')
.option('-m, --metadata <metadata...>', 'field=name[@version] producer metadata to add with the embedding')
.action(asyncAction(componentEmbed));

program.showHelpAfterError();

program.parse();

function asyncAction (cmd) {
Expand Down

0 comments on commit d32d2ae

Please sign in to comment.