Skip to content

Repl: emit warning for the :sh command #22694

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

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/repl/ParseResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ object Reset {
val command: String = ":reset"
}

/** `:sh <command line>` 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"
Expand Down Expand Up @@ -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),
)

Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/i21657
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scala>:sh
The :sh command is deprecated. Use `import scala.sys.process._` and `"command".!` instead.
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/repl/TabcompleteTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class TabcompleteTests extends ReplTest {
":quit",
":reset",
":settings",
":sh",
":silent",
":type"
),
Expand Down