Skip to content

fix(run): accept - as the stdin script argument#39

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/run-stdin-dash-rejected
Jul 26, 2026
Merged

fix(run): accept - as the stdin script argument#39
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/run-stdin-dash-rejected

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

The documented stdin form moshcode run - < script.mosh exits 1 with unknown option -.

Reproduce

$ echo 'say("hi from stdin")' | moshcode run -
moshcode run: unknown option -
$ echo $?
1

Cause

readScript() already handles the bare - (bin/moshcode.mjs:37):

if (!arg || arg === "-") return fs.readFileSync(0, "utf8"); // stdin (paste)

But the option parser rejects it first (bin/moshcode.mjs:289), because - starts with a dash and no positional has been seen yet:

else if (a.startsWith("-") && positional.length === 0) {
  console.error(`moshcode run: unknown option ${a}`);
  process.exit(1);
}

So the stdin path is unreachable from the CLI. It is documented in two places: README.md:164 (moshcode run - < script.mosh # pipe/paste from stdin) and the comment at bin/moshcode.mjs:56.

Fix

Exclude the bare - from the leading-dash check so it falls through to positional, where readScript() picks it up.

else if (a !== "-" && a.startsWith("-") && positional.length === 0) {

Verification

$ echo 'say("hi from stdin")' | node bin/moshcode.mjs run -
  💬 hi from stdin
$ echo $?
0

$ node bin/moshcode.mjs run --bogus
moshcode run: unknown option --bogus     # still exits 1

Added run - reads the script from stdin to test/run-options.test.mjs. It fails on master (not ok 88) and passes with the fix. Full suite: 146/146 pass, up from 145 baseline.

`moshcode run - < script.mosh` is documented in README.md and handled
explicitly by readScript(), but the option parser treated the bare `-`
as an unknown option and exited 1 before it could be used.

Exclude `-` from the leading-dash check so it falls through to the
positional argument, where readScript() already reads stdin. Unknown
options such as --bogus still exit 1 as before.
@ralyodio
ralyodio merged commit 6348397 into moshcoder:main Jul 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants