tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
356 stars 100 forks source link

Double dash in CLI doesn't stop argument processing #583

Open novusnota opened 2 months ago

novusnota commented 2 months ago

Problem

For example, consider the following instruction:

npx tact -e -- '-1 + 1'

The expected result would be 0, but instead one gets an exit code 2 and the following:

Unknown flag
-1 + 1

Notes

Did some research, and it's probably related to poorly resolved closed and unresolved stale issues regarding this case in yargs-parser, which meow (our CLI toolkit) uses for parsing arguments. It may be time to consider moving to another CLI toolkit. Commander.js is quite nice and is rather friendly towards #446, see https://github.com/tj/commander.js/issues/2008 (or we'll just duplicate some flags here and there, no biggie)

As a temporary (ha!) workaround one may just put 0 + in front of any expression and remove the --. Like so:

npx tact -e '0 + -1 + 1'
anton-trunov commented 2 months ago

It may be time to consider moving to another CLI toolkit. Commander.js is quite nice

is there a native typescript cli parser?

novusnota commented 2 months ago

is there a native typescript cli parser?

No — there's no argument parser in Node.js APIs and TypeScript doesn't add APIs on top. One just gets process.argv and has to start from there :/

What works - works, and it's not a pressing issue considering that leading dashes are much less likely to occur in the context of files than in the context of evaluating expressions after -e/--expr. So the 0 + ... workaround is good enough for a while