Skip to content

Make inputs optional when -classpath and --main-class are passed #1369

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

Conversation

Gedochao
Copy link
Contributor

Context

The scala command allows to do the following:

▶ ls
Main.scala
▶ mkdir out
▶ scalac Main.scala -d out
▶ scala Main -classpath out
Hello

Meanwhile, Scala CLI:

  • passing the -classpath option out of the blue will just start the repl with the relevant classpath. this still allows to run whatever you want in the repl. We are keeping this behaviour.
▶ scala-cli -classpath out
Welcome to Scala 3.2.0 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                                                         
scala> Main.main(Array.empty)
Hello
  • it becomes more confusing if you try to pass the main class with the --main-class option, similarly to how the scala command allows to pass it as an input.
▶ scala-cli --main-class Main -classpath out
Unrecognized argument: --main-class

To list all available options, run
  scala-cli --help

This fails, as --main-class isn't an option for the repl, and we are defaulting to the repl.
Still, if we pass the run sub-command explicitly, it fails as well.

▶ scala-cli run --main-class Main -classpath out
[error]  No inputs provided (expected files with .scala, .sc, .java or .md extensions, and / or directories).

Even though the main class is specified and it is indeed passed on the classpath, scala-cli fails because it expects inputs.

After the changes

TL;DR the following syntax becomes available:

  • if the run sub-command is passed explicitly, it's sufficient to have a main class on the classpath, inputs aren't necessary then
▶ scala-cli run -classpath out          
Hello
  • when using the default command, --main-class has to be passed explicitly (even if there's only one main class on the classpath) to indicate the intent of running it instead of defaulting to the repl
▶ scala-cli --main-class Main -classpath out
Hello
  • just passing the -classpath still defaults to the repl
▶ scala-cli -classpath out                  
Welcome to Scala 3.1.3 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                                                         
scala> Main.main(Array.empty)
Hello

@Gedochao Gedochao added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Sep 15, 2022
@Gedochao Gedochao force-pushed the backwards-compat-classpat-and-main-class-inputs branch from cc6198b to b860d18 Compare September 15, 2022 13:12
@Gedochao Gedochao force-pushed the backwards-compat-classpat-and-main-class-inputs branch from b860d18 to fe791de Compare September 15, 2022 13:58
@mpkocher
Copy link
Contributor

It looks like the root behavior has/is become quite complex. How are all of these different cases communicated in --help?

@Gedochao
Copy link
Contributor Author

Gedochao commented Sep 16, 2022

It looks like the root behavior has/is become quite complex. How are all of these different cases communicated in --help?

@mpkocher they aren't just yet, but we are planning some docs and -help improvements tied to the SIP changes down the line.

EDIT: I created a catch-all ticket to track those - #1370

@Gedochao Gedochao merged commit 880242e into VirtusLab:main Sep 16, 2022
@Gedochao Gedochao deleted the backwards-compat-classpat-and-main-class-inputs branch September 16, 2022 13:43
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