Skip to content

Commit fba0365

Browse files
committed
fix(cli): accept stdin script marker
1 parent dfcb8c1 commit fba0365

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

bin/moshcode.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ async function main() {
303303
catch (e) { console.error(String(e.message || e)); process.exit(1); }
304304
}
305305
else if (a === "--dry-run") dryRun = true;
306-
else if (a !== "-" && a.startsWith("-") && positional.length === 0) {
306+
else if (a.startsWith("-") && a !== "-" && positional.length === 0) {
307307
console.error(`moshcode run: unknown option ${a}`);
308308
process.exit(1);
309309
}

test/run-options.test.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { closeSync, mkdtempSync, openSync, readFileSync, writeFileSync } from "n
33
import { fileURLToPath } from "node:url";
44
import { tmpdir } from "node:os";
55
import { join } from "node:path";
6-
import { spawn } from "node:child_process";
6+
import { spawn, spawnSync } from "node:child_process";
77
import test from "node:test";
88

99
const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url));
@@ -75,6 +75,17 @@ test("run - reads the script from stdin", async () => {
7575
assert.match(result.stdout, /from stdin/);
7676
});
7777

78+
test("run accepts - before --dry-run", () => {
79+
const result = spawnSync(process.execPath, [BIN, "run", "-", "--dry-run"], {
80+
encoding: "utf8",
81+
input: 'say("from stdin");\n',
82+
});
83+
84+
assert.equal(result.status, 0);
85+
assert.equal(result.stderr, "");
86+
assert.match(result.stdout, /from stdin/);
87+
});
88+
7889
test("run accepts equals-form max option", async () => {
7990
const result = await run(["--max=1", "--dry-run"]);
8091

0 commit comments

Comments
 (0)