Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backwards compat for -e and --scalac-help #1313

Merged
merged 3 commits into from
Sep 5, 2022

Conversation

Gedochao
Copy link
Contributor

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).

@Gedochao Gedochao added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Aug 31, 2022
@mpkocher
Copy link
Contributor

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?

@Gedochao
Copy link
Contributor Author

Gedochao commented Sep 1, 2022

@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.

@Gedochao Gedochao merged commit 6def0c0 into VirtusLab:main Sep 5, 2022
@Gedochao Gedochao deleted the fix-default-e-script-snippets branch September 5, 2022 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants