janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.43k stars 221 forks source link

Add default output path for --compile (-c) #1472

Closed Andriamanitra closed 1 month ago

Andriamanitra commented 1 month ago

Changes behavior of -c flag such that:

Previously these would cause a confusing error due to out of bounds access to the args array (see #1451).

The default is only used if there are no more arguments after the input file – I didn't add any special handling for edge cases like janet -c foo.janet -h (which uses '-h' as the output file).

closes #1451

sogaiu commented 1 month ago

Gave the changes a try.

Both invocations seemed to work :+1:

When a file named foo did not exist I got an error like:

error: could not find file foo
  in dofile [boot.janet] on line 2966, column 5
  in c-switch [boot.janet] (tail call) on line 4477, column 19
  in cli-main [boot.janet] on line 4520, column 13

which seemed helpful.