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

Running Scala CLI without any arguments should start a REPL #1249

Closed
romanowski opened this issue Aug 15, 2022 · 6 comments · Fixed by #1305
Closed

Running Scala CLI without any arguments should start a REPL #1249

romanowski opened this issue Aug 15, 2022 · 6 comments · Fixed by #1305
Assignees
Labels
SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command.

Comments

@romanowski
Copy link
Member

Is your feature request related to a problem? Please describe.

This issue was created based on the comments in Scala CLI SIP.

The current scala command starts repl with no arguments provided but with scala-cli repl subcommand is needed. I think we should change the behaviour to match what scala is doing now: running repl when no commands are provided.

Describe the solution you'd like

When running scala-cli without any command, a reply should be started.

Additional context

We would need to find a way to display help for the whole scala-cli' tool. With the default changed, user running scala-cli --helpmay expect either help for the wholescala-clior therepl` command. I can see 2 options:

  • scala-cli --help prints the help for the whole tool with the mention that to see a help dedicated for repl command run scala-cli repl --help
  • scala-cli --help prints the help for repl command with the mention that to see the whole help run e.g. scala-cli --help --all

I am personally prefer the former mechanism.

@bjornregnell
Copy link
Contributor

bjornregnell commented Aug 15, 2022

I am personally prefer the former mechanism.

I agree - it would also bee good if all of these gave the help text for the whole tool:

scala -h
scala -help
scala --help
scala help

Even if it is not "consistent" to have them all it is great UX for the aspect of discoverability, as we cannot assume that at novice knows the boundaries within what input is deemed "consistent" :)

@romanowski romanowski added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Aug 15, 2022
@sideeffffect
Copy link

sideeffffect commented Aug 15, 2022

CLI tools typically print the help text on bad usage. We can keep only the "traditional" -h and --help. Even if you type nonexistent switch (like -help), you will still be show the help text.

@bjornregnell
Copy link
Contributor

bjornregnell commented Aug 16, 2022

It would be good to make sure that it also works as before with scala-cli to give the -S or --scala-version options (and perhaps other relevant options to scala-cli). So instead of:

$ scala-cli repl -S 2
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.3).
Type in expressions for evaluation. Or try :help.

scala> 

$ scala-cli repl -S 3
Welcome to Scala 3.1.3 (17.0.3, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> 

We can write just:

$ scala -S 2
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.3).
Type in expressions for evaluation. Or try :help.

scala> 

$ scala -S 3
Welcome to Scala 3.1.3 (17.0.3, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> 

@Gedochao
Copy link
Contributor

CLI tools typically print the help text on bad usage. We can keep only the "traditional" -h and --help. Even if you type nonexistent switch (like -help), you will still be show the help text.

FYI we already have a ticket for this: #1240

@mpkocher
Copy link
Contributor

Isn't there's a friction point with the project/file(s) being passed to scala-cli repl as a positional arg(s) being mapped to the root layer?

I suspect that supporting these positional args at the root level will create ambiguities with the subcommands. Or scala-cli repl and scala-cli (with no positional args) would have different behavior/semantics?

https://scala-cli.virtuslab.org/docs/commands/repl

There is a fundamental collision issue of project names (e.g., "test") and subcommands if you try to load positional args at the root level. This currently exists with scala-cli's current model that implicitly tries to dispatch to scala-cli run at the root level. Changing this to dispatch to scala-cli repl will have the same potential collision issues.

#1240 (comment)

There's a bit more surface area and functionality of scala-cli vs the current scala tool. As such, scala-cli has organized this functionality in a very approachable and explorable fashion with the subcommand design.

It might be useful to try to embrace the subcommand design of scala-cli instead of trying to have a guessing layer at the root that dispatches to a specific subcommand. The subcommand model git has adopted doesn't seem to hinder its adoption.

@bjornregnell
Copy link
Contributor

bjornregnell commented Aug 23, 2022

Yes, the sub-command UI is very clear and consistent once you get it. What I mean is that some limited selected things (starting repl, getting help, checking version) are special-cased at top-level to make it simple for beginners and (somewhat) backward compatible with the old scala command. Other stuff from the old scala command that are too much interfeering with the sub-command-idea should give good error hints that are implemented also with those used to the old scala command in mind, if possible.

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
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants