Impossible to pass arguments to Node.js (using `--nodejs`) and execute a script from file name at the same time
Context
- commit: 55ada776d82c06c274cd5e976c62d15a0c1f2fd9
Examples
Let me describe by examples:
lsc --nodejs --harmony --harmony-proxieswill work as expected, but will start interactive modelsc --nodejs --harmony --harmony-proxies index.ls -a -b arg1 arg2won'tlsc index.ls -a -b arg1 arg2 --nodejs --harmony --harmony-proxieswon't either
Problem statement
The actual problem comes from the requirement: being able to pass an arbitrary sequence of arguments both for the invoked user program and for the Node.js executable.
Indeed, the second example will pass everything to Node.js, while the third will pass everything to the user program.
Investigation
I tried implementing different arguments processing before realizing the statement above: no implementation will allow passing any argument to any of these two programs (in this case we would forbid passing --nodejs/-n to user programs, or forbid passing purely positional arguments to Node.js).
Am I missing something?
If true, what would be suitable alternatives to input arguments without conflict?
The key is not to merge things that can conflict when present in one single input. Here are the different ones I'm thinking of regarding the invocation of a program:
- stdin: but already used to read the user program content if
-sis activated - command line
- directly as a string: in this case can we fully escape everything to write an embedded command line?
- path to a file containing the string: but this requires having a file containing the list of arguments, not handy
Several points:
lscarguments always need to be passed before the script name. Otherwise we consider they're script arguments (no other way here).- The arguments to the
--nodejsflag, AFAIK, must be passed all at once (again, we can't know otherwise).
Use this line to invoke your script instead:
lsc --nodejs '--harmony --harmony-proxies' index.ls -a -b arg1 arg2
and tell us if that solves your issue.
I didn't mention passing arguments to lsc itself, I described passing arbitrary arguments to Node.js and to the user program (the script). In fact, the point you mentioned is correct, lsc will consider all positional arguments to be at the end of the command line, and to correspond to [script_name, ...script_args]. It's its way to get the arbitrary arguments for the script.
However for the Node.js arguments it's a bit different:
- if
--nodejsis at the end, it will be captured byscript_argsand won't be detected (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/command.ls#L41), therefore passed as is to the script. - if it's before, everything after
--nodejswill be captured and passed to Node.js, therefore making it impossible to pass positional arguments tolsc.
It's because the arguments list for Node.js is not input as a String (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/options.ls#L52) and just eats the rest of the command line (https://github.com/gkz/LiveScript/blob/55ada776d82c06c274cd5e976c62d15a0c1f2fd9/src/options.ls#L54).
you also can't currently combine -e, -c, and -p), to compile a one liner without saving it first or using stdin/repl (compile from command line as input)
This is still a thing. Makes it impossible to start Node in debug mode.
-
--nodejsbefore file namelsc --nodejs 'inspector' main.lsThis does the equivalent of
node inspector main.ls, starting in debug mode but dying on syntax error. -
--nodejsafter file namelsc main.ls --nodejs 'inspector'This just passes
--nodejsand'inspector'as arguments tomain.ls, and doesn't start in debug mode.
What do you think of a fix that makes --nodejs take String instead of Boolean as it does currently?
Might have to child_process.exec node over here in command.ls instead instead of child_process.spawn, so any quoted stuff and spaces in that --nodejs option string are handled according to the expected shell rules?
What do you think of a fix that makes
--nodejstakeStringinstead ofBooleanas it does currently?
That's how CoffeeScript has it. :+1: for me.