Commit 57a5b80b

57a5b80b06d0Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

spinel: support `--` to end CLI flag parsing

A leading `--` (before the .rb source) ends spinel's own flag parsing — the next token becomes the source. In -E mode any remaining tokens become the binary's ARGV.

`--` after the source name is left untouched (it shows up in ARGV verbatim, matching CRuby's `ruby script.rb -- foo`).

Fixes #835

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
57a5b80b06d0
Parent
885048a6e745

spinelmodifiedView file

@@ -73,6 +73,28 @@
7373 --rbs) shift; RBS_DIR="$1"; shift ;;
7474 --int-overflow=*) INT_OVERFLOW="${1#--int-overflow=}"; shift ;;
7575 --int-overflow) shift; INT_OVERFLOW="$1"; shift ;;
76+ --) # `--` ends spinel-flag parsing (issue #835).
77+ # In -E (run) mode the remaining args become ARGV
78+ # for the compiled binary; in compile mode the next
79+ # token is treated as the source path (matching ruby).
80+ shift
81+ if [ "$RUN_MODE" -eq 1 ]; then
82+ if [ -z "$SOURCE" ] && [ $# -gt 0 ]; then
83+ SOURCE="$1"
84+ shift
85+ fi
86+ break
87+ fi
88+ if [ -z "$SOURCE" ] && [ $# -gt 0 ]; then
89+ SOURCE="$1"
90+ shift
91+ fi
92+ # Anything left after the source is ignored in
93+ # compile-only mode (matches ruby's behaviour where
94+ # trailing args become ARGV — but spinel doesn't run
95+ # the program here).
96+ break
97+ ;;
7698 -o) shift; OUTPUT="$1"; shift ;;
7799 -O) shift; OPT_LEVEL="$1"; shift ;;
78100 -e) shift