scala-cli
scala-cli copied to clipboard
Fix backwards compat for `-e` and `--scalac-help`
As we now default to the repl sub-command when no args are passed, the -e option requires special handling.
Normally, adding a script snippet for the repl just adds it on the classpath.
▶ scala-cli repl -e 'println("Hello")'
Welcome to Scala 3.1.3 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> snippet_sc.main(Array.empty)
Hello
scala>
However, the scala command's -e option's behaviour is closer to the run sub-command of Scala CLI.
And so, when scala-cli is being run without the repl sub-command passed explicitly, passing -e will now default to run.
▶ scala-cli -e 'println("Hello")'
Hello
Using the --script-snippet alias instead of -e will still pass the snippet to the repl.
▶ scala-cli --script-snippet 'println("Hello")'
Welcome to Scala 3.1.3 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> snippet_sc.main(Array.empty)
Hello
Also, this PR fixes --scalac-help (and other help options passed to the compiler through --scalac-option) and adds --help-scalac as an alias).
Isn't this creating a bunch of entropy by creating all of these special cases and duplication with scala-cli run and scala-cli repl?
At a minimum this will create a bit of cognitive overhead and confusion for new users when examples/docs/people are using different styles?
@mpkocher Our aim is to maximize backwards compatibility with the old scala runner command (to fulfill the requirements of SIP-46) while at the same time minimizing changes to the current scala-cli behaviour.
scala's -e option is a bit of a niche, barely documented feature.
it's not even mentioned in dotty's scala runner's help (the only mention I know of is the 3.1.2's release notes)
So AFAIK it's only properly documented in Scala 2's help
Still, as it may have some people relying on it regardless, we want the transition seemless.
For scala-cli, -e is merely an alias for --script-snippet.
I understand your concerns, but IMO the confusion should be minimal.