leafo/moonscript

"Read from stdin" broken in moonc

Sharparam opened this issue · 5 comments

According to the output of moonc -h, supplying the option - (and no other option) is supposed to read from stdin and output to stdout, but this doesn't seem to work:

$ moonc -
-       Can't find file  

Supplying the /dev/stdin works to circumvent it at least on Linux, but it makes for very wordy commands like:

$ cat <<EOF | moonc -p /dev/stdin
print 'Hello, World!'
EOF
return print('Hello, World!')  

I think it is --, not -.

It seems the help message in the dev version has changed, but the actual check still looks for --.

Here's the help message from dev version of moonc (luarocks install moonscript --dev):

❯ moonc -h
Usage: /usr/lib/luarocks/rocks-5.4/moonscript/dev-1/bin/moonc
       ([-t <output_to>] | [-o <o>] | [-p] | [-T] | [-b] | [-X]) [-h]
       [-l] [-v] [-w] [--transform <transform>] [-]
       <file/directory> [<file/directory>] ...

Arguments:
   file/directory

Options:
   -h, --help            Show this help message and exit.
   -l, --lint            Perform a lint on the file instead of compiling
   -v, --version         Print version
   -w, --watch           Watch file/directory for updates
   --transform <transform>
                         Transform syntax tree with module
            -t <output_to>,
   --output-to <output_to>
                         Specify where to place compiled files
   -o <o>                Write output to file
   -p                    Write output to standard output
   -T                    Write parse tree instead of code (to stdout)
   -b                    Write parse and compile time instead of code(to stdout)
   -X                    Write line rewrite map instead of code (to stdout)
   -                     Read from standard in, print to standard out (Must be only argument)

Does it work when you do -- or is it only a problem with docs?

Using -- makes it work as expected yeah. So it's either the docs being wrong, or the code parsing wrong. A single dash is what I would expect, since that's how most unix commands function (a single dash to process stdin, two dashes to stop options processing, so everything after -- is treated as filenames).

Yeah, I'd expect (and prefer) - too.

Although 9d11356 added it as -- and dd9661d broke it. I guess leafo will indicate his preference on your PR.