Skip to content

Add support for the :sh command in the REPL #21657

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

Closed
Gedochao opened this issue Sep 27, 2024 · 6 comments · Fixed by #22694
Closed

Add support for the :sh command in the REPL #21657

Gedochao opened this issue Sep 27, 2024 · 6 comments · Fixed by #22694
Assignees
Labels
area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. itype:enhancement
Milestone

Comments

@Gedochao
Copy link
Contributor

The :sh command was (and is) supported by the Scala 2 REPL, while it is visibly absent in Scala 3.

scala -S 2.13
Welcome to Scala 2.13.15 (OpenJDK 64-Bit Server VM, Java 17).
Type in expressions for evaluation. Or try :help.
scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
(...)
:sh <command line>       run a shell command (result is implicitly => List[String])
(...)
scala> :sh scala-cli --help
val res9: scala.tools.nsc.interpreter.shell.ProcessResult = `scala-cli --help` (54 lines, exit 0)

scala> res9.lines.mkString(System.lineSeparator)
val res10: String =
Usage: scala-cli <COMMAND>
Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run and test your Scala code.

Main commands:
  clean                  Clean the workspace.
  compile                Compile Scala code.
  doc                    Generate Scaladoc documentation.
  fmt, format, scalafmt  Formats Scala code.
  repl, console          Fire-up a Scala REPL.
  run                    Compile and run Scala code.
  test                   Compile and test Scala code.

Miscellaneous commands:
  version  Prints the version of the Scala CLI and the default version of Scala.

Other commands:
  config    ...
@Gedochao Gedochao added itype:enhancement area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. labels Sep 27, 2024
@mbovel
Copy link
Member

mbovel commented Jan 9, 2025

I started looking into this and noticed that the Scala 2 implementation returns a scala.tools.nsc.interpreter.shell.ProcessResult object. scala.tools.nsc mainly seems to contain Scala 2-related things. Would we want to continue using it for a Scala 3 implementation? Are we committed to maintain these APIs?

An alternative that also works outside of the REPL is scala.sys.process:

  ~ scala -S 3.6.2
Jan 09, 2025 4:49:11 PM org.jline.utils.Log logr
WARNING: The terminal provider jna has been deprecated, check your configuration. This warning can be disabled by setting the system property org.jline.terminal.disableDeprecatedProviderWarning to true.
Welcome to Scala 3.6.2 (21.0.5, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                
scala> import scala.sys.process.*
                                                                                
scala> "scala-cli --help".!
Usage: scala-cli <COMMAND>
Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test and package your Scala code.
...

What would be the advantage of having a specific :sh REPL command compared to using scala.sys.process?

@SethTisue
Copy link
Member

SethTisue commented Jan 11, 2025

I'd forgotten :sh even exists; I don't recall ever hearing anyone ever mention it.

@mbovel
Copy link
Member

mbovel commented Jan 13, 2025

What you you think @Gedochao:

  • Is it worth investing in :sh when we already havescala.sys.process?
  • If we do, should it use scala.tools.nsc.interpreter.shell as the Scala 2 implementation?

@Gedochao
Copy link
Contributor Author

@mbovel I'll raise it on core today

@Gedochao Gedochao added the stat:needs decision Some aspects of this issue need a decision from the maintainance team. label Jan 15, 2025
@tgodzik
Copy link
Contributor

tgodzik commented Jan 22, 2025

The conclusions is that we should deprecate it in Scala 2, which already has the ticket (above) and Scala 3 should have a proper error message on how to work around the missing feature.

@Gedochao
Copy link
Contributor Author

The conclusions is that we should deprecate it in Scala 2, which already has the ticket (above) and Scala 3 should have a proper error message on how to work around the missing feature.

@mbovel calling :sh in the Scala 3 REPL should print a warning, informing that it is not supported in Scala 3 and suggesting to call scala.sys.process.Process(_).! directly.

@mbovel mbovel removed the stat:needs decision Some aspects of this issue need a decision from the maintainance team. label Jan 23, 2025
@mbovel mbovel assigned bracevac and unassigned mbovel Jan 30, 2025
bracevac added a commit to dotty-staging/dotty that referenced this issue Mar 2, 2025
bracevac added a commit that referenced this issue Mar 3, 2025
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants