diff --git a/modules/cli/src/main/scala/scala/cli/commands/default/LegacyScalaOptions.scala b/modules/cli/src/main/scala/scala/cli/commands/default/LegacyScalaOptions.scala index 65b9a1d994..d234265513 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/default/LegacyScalaOptions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/default/LegacyScalaOptions.scala @@ -46,6 +46,13 @@ case class LegacyScalaOptions( @Name("-nc") @Name("-nocompdaemon") noCompilationDaemon: Option[Indexed[Boolean]] = None, + @Group("Legacy Scala runner") + @HelpMessage("Ignored legacy option. Deprecated option allowing to force the `run` mode on an input.") + @Tag(tags.must) + @Hidden + @ValueDescription("file") + @Name("-run") + run: Option[Indexed[String]] = None, ) { // format: on @@ -64,8 +71,16 @@ case class LegacyScalaOptions( val howToRunString = howToRun.findArg(args) val iString = I.findArg(args) val noCompilationDaemonString = noCompilationDaemon.findArg(args) + val runString = run.findArg(args) val deprecatedArgs = - Seq(saveOptionString, noSaveOptionString, howToRunString, iString, noCompilationDaemonString) + Seq( + saveOptionString, + noSaveOptionString, + howToRunString, + iString, + noCompilationDaemonString, + runString + ) .flatten val filteredArgs = args.filterNot(deprecatedArgs.contains) val filteredArgsString = filteredArgs.mkString(" ") @@ -126,6 +141,20 @@ case class LegacyScalaOptions( logger.message(s"Deprecated option '$nc' is ignored.") logger.message("The script runner can no longer be picked as before.") } + for { + rString <- runString + rValue <- run.map(_.value) + } { + logger.message(s"Deprecated option '$rString' is ignored.") + logger.message( + s"""$fullRunnerName does not support explicitly forcing the old `run` mode. + |Just pass $rValue as input and make sure it has the correct format and extension. + |i.e. to run a JAR, pass it as an input, just make sure it has the `.jar` extension and a main class. + |For details on how inputs can be run with $fullRunnerName, check the `run` sub-command. + | ${Console.BOLD}$progName run --help${Console.RESET} + |""".stripMargin + ) + } filteredArgs } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/LegacyScalaRunnerTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/LegacyScalaRunnerTestDefinitions.scala index 16f6a8e033..e81a71ab89 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/LegacyScalaRunnerTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/LegacyScalaRunnerTestDefinitions.scala @@ -40,10 +40,11 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests => test("ensure -howtorun/--how-to-run works with the default command") { legacyOptionBackwardsCompatTest("-howtorun", "--how-to-run") { - (legacyHtrOption, root) => + (legacyHtrOption, inputFile, root) => Seq("object", "script", "jar", "repl", "guess", "invalid").foreach { htrValue => - val res = os.proc(TestUtil.cli, legacyHtrOption, htrValue, "s.sc", TestUtil.extraOptions) - .call(cwd = root, stderr = os.Pipe) + val res = + os.proc(TestUtil.cli, legacyHtrOption, htrValue, inputFile, TestUtil.extraOptions) + .call(cwd = root, stderr = os.Pipe) expect(res.err.trim().contains(deprecatedOptionWarning(legacyHtrOption))) expect(res.err.trim().contains(htrValue)) } @@ -52,10 +53,21 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests => test("ensure -I works with the default command") { legacyOptionBackwardsCompatTest("-I") { - (legacyOption, root) => - val res = os.proc(TestUtil.cli, legacyOption, "--repl-dry-run", TestUtil.extraOptions) + (legacyOption, inputFile, root) => + val anotherInputFile = "smth.scala" + val res = os.proc( + TestUtil.cli, + legacyOption, + inputFile, + legacyOption, + anotherInputFile, + "--repl-dry-run", + TestUtil.extraOptions + ) .call(cwd = root, stderr = os.Pipe) expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption))) + expect(res.err.trim().contains(inputFile)) + expect(res.err.trim().contains(anotherInputFile)) } } @@ -63,29 +75,44 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests => simpleLegacyOptionBackwardsCompatTest("-nc", "-nocompdaemon", "--no-compilation-daemon") } + test("ensure -run works with the default command") { + legacyOptionBackwardsCompatTest("-run") { + (legacyOption, inputFile, root) => + val res = os.proc(TestUtil.cli, legacyOption, inputFile, ".", TestUtil.extraOptions) + .call(cwd = root, stderr = os.Pipe) + expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption))) + expect(res.err.trim().contains(inputFile)) + } + } + private def simpleLegacyOptionBackwardsCompatTest(optionAliases: String*): Unit = abstractLegacyOptionBackwardsCompatTest(optionAliases) { - (legacyOption, expectedMsg, root) => + (legacyOption, expectedMsg, _, root) => val res = os.proc(TestUtil.cli, legacyOption, "s.sc", TestUtil.extraOptions) .call(cwd = root, stderr = os.Pipe) expect(res.out.trim() == expectedMsg) expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption))) } - private def legacyOptionBackwardsCompatTest(optionAliases: String*)(f: (String, os.Path) => Unit) - : Unit = - abstractLegacyOptionBackwardsCompatTest(optionAliases) { (legacyOption, _, root) => - f(legacyOption, root) + private def legacyOptionBackwardsCompatTest(optionAliases: String*)(f: ( + String, + String, + os.Path + ) => Unit): Unit = + abstractLegacyOptionBackwardsCompatTest(optionAliases) { (legacyOption, _, inputFile, root) => + f(legacyOption, inputFile, root) } private def abstractLegacyOptionBackwardsCompatTest(optionAliases: Seq[String])(f: ( + String, String, String, os.Path ) => Unit): Unit = { - val msg = "Hello world" - TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root => - optionAliases.foreach(f(_, msg, root)) + val msg = "Hello world" + val inputFile = "s.sc" + TestInputs(os.rel / inputFile -> s"""println("$msg")""").fromRoot { root => + optionAliases.foreach(f(_, msg, inputFile, root)) } }