diff --git a/compiler/src/dotty/tools/repl/ParseResult.scala b/compiler/src/dotty/tools/repl/ParseResult.scala index 2674a385a10c..dd4c5d80a9e1 100644 --- a/compiler/src/dotty/tools/repl/ParseResult.scala +++ b/compiler/src/dotty/tools/repl/ParseResult.scala @@ -100,6 +100,12 @@ object Reset { val command: String = ":reset" } +/** `:sh ` run a shell command (result is implicitly => List[String]) */ +case class Sh(expr: String) extends Command +object Sh { + val command: String = ":sh" +} + /** Toggle automatic printing of results */ case object Silent extends Command: val command: String = ":silent" @@ -150,6 +156,7 @@ object ParseResult { TypeOf.command -> (arg => TypeOf(arg)), DocOf.command -> (arg => DocOf(arg)), Settings.command -> (arg => Settings(arg)), + Sh.command -> (arg => Sh(arg)), Silent.command -> (_ => Silent), ) diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index b00cf3d19188..47cd6fb133ef 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -538,6 +538,10 @@ class ReplDriver(settings: Array[String], } state + case Sh(expr) => + out.println(s"""The :sh command is deprecated. Use `import scala.sys.process._` and `"command".!` instead.""") + state + case Settings(arg) => arg match case "" => given ctx: Context = state.context diff --git a/compiler/test-resources/repl/i21657 b/compiler/test-resources/repl/i21657 new file mode 100644 index 000000000000..fa2eec3ac891 --- /dev/null +++ b/compiler/test-resources/repl/i21657 @@ -0,0 +1,2 @@ +scala>:sh +The :sh command is deprecated. Use `import scala.sys.process._` and `"command".!` instead. \ No newline at end of file diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 66c0fd8a9ce7..95312b51497b 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -218,6 +218,7 @@ class TabcompleteTests extends ReplTest { ":quit", ":reset", ":settings", + ":sh", ":silent", ":type" ),