Skip to content

Commit abce9e8

Browse files
committed
Include legacy scala runner options in the help
1 parent 01de592 commit abce9e8

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

modules/cli/src/main/scala/scala/cli/commands/ScalaCommandWithCustomHelp.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import caseapp.core.Error
44
import caseapp.core.help.{Help, HelpCompanion, RuntimeCommandsHelp}
55
import caseapp.core.parser.Parser
66

7-
import scala.cli.commands.default.DefaultOptions
7+
import scala.cli.commands.default.{DefaultOptions, LegacyScalaOptions}
88
import scala.cli.commands.shared.{HasLoggingOptions, ScalaCliHelp}
99
import scala.cli.commands.util.HelpUtils.*
1010
import scala.cli.launcher.LauncherOptions
@@ -18,12 +18,23 @@ abstract class ScalaCommandWithCustomHelp[T <: HasLoggingOptions](
1818
) extends ScalaCommand[T] {
1919
private def launcherHelp: Help[LauncherOptions] = HelpCompanion.deriveHelp[LauncherOptions]
2020

21+
private def legacyScalaHelp: Help[LegacyScalaOptions] =
22+
HelpCompanion.deriveHelp[LegacyScalaOptions]
23+
2124
protected def customHelp(showHidden: Boolean): String = {
22-
val helpString = actualHelp.help(helpFormat, showHidden)
23-
val launcherHelpString = launcherHelp.optionsHelp(helpFormat, showHidden)
25+
val helpString = actualHelp.help(helpFormat, showHidden)
26+
val launcherHelpString = launcherHelp.optionsHelp(helpFormat, showHidden)
27+
val legacyScalaHelpString = legacyScalaHelp.optionsHelp(helpFormat, showHidden)
28+
val legacyScalaHelpStringWithPadding =
29+
if legacyScalaHelpString.nonEmpty then
30+
s"""
31+
|$legacyScalaHelpString
32+
|""".stripMargin
33+
else ""
2434
s"""$helpString
2535
|
26-
|$launcherHelpString""".stripMargin
36+
|$launcherHelpString
37+
|$legacyScalaHelpStringWithPadding""".stripMargin
2738
}
2839

2940
protected def customHelpAsked(showHidden: Boolean): Nothing = {

modules/cli/src/main/scala/scala/cli/commands/default/Default.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Default(
2222

2323
private lazy val defaultCommandHelp: String =
2424
s"""
25-
|
2625
|When no subcommand is passed explicitly, an implicit subcommand is used based on context:
2726
| - if the '--version' option is passed, it prints the 'version' subcommand output, unmodified by any other options
2827
| - if any inputs were passed, it defaults to the 'run' subcommand

modules/cli/src/main/scala/scala/cli/commands/default/LegacyScalaOptions.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,35 @@ import scala.cli.commands.tags
1414
*/
1515
// format: off
1616
case class LegacyScalaOptions(
17-
@Group("Scala")
17+
@Group("Legacy Scala runner")
1818
@HelpMessage(s"Ignored legacy option. Deprecated equivalent of running a subsequent `$PowerString${Package.name}` command.")
1919
@Tag(tags.must)
20+
@Hidden
2021
@Name("-save")
2122
save: Option[Indexed[Boolean]] = None,
22-
@Group("Scala")
23+
@Group("Legacy Scala runner")
2324
@HelpMessage("Ignored legacy option. Deprecated override canceling the `-nosave` option.")
2425
@Tag(tags.must)
26+
@Hidden
2527
@Name("-nosave")
2628
nosave: Option[Indexed[Boolean]] = None,
27-
@Group("Scala")
29+
@Group("Legacy Scala runner")
2830
@HelpMessage("Ignored legacy option. Deprecated override defining how the runner should treat the input. Use the appropriate sub-command instead.")
2931
@Tag(tags.must)
32+
@Hidden
3033
@ValueDescription("object|script|jar|repl|guess")
3134
@Name("-howtorun")
3235
howToRun: Option[Indexed[String]] = None,
33-
@Group("Scala")
36+
@Group("Legacy Scala runner")
3437
@HelpMessage("Ignored legacy option. Deprecated option allowing to preload inputs for the repl or command execution.")
3538
@Tag(tags.must)
39+
@Hidden
3640
@ValueDescription("file")
3741
I: Option[Indexed[List[String]]] = None,
38-
@Group("Scala")
42+
@Group("Legacy Scala runner")
3943
@HelpMessage("Ignored legacy option. Deprecated option allowing to prevent the use of the legacy fsc compilation daemon.")
4044
@Tag(tags.must)
45+
@Hidden
4146
@Name("-nc")
4247
@Name("-nocompdaemon")
4348
noCompilationDaemon: Option[Indexed[Boolean]] = None,

modules/integration/src/test/scala/scala/cli/integration/HelpTests.scala

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,46 @@ class HelpTests extends ScalaCliSuite {
2525
test(s"$helpOptionsString output includes launcher options") {
2626
expect(helpOutput.contains("--power"))
2727
}
28+
29+
test(s"$helpOptionsString output does not include legacy scala runner options") {
30+
expect(!helpOutput.contains("Legacy Scala runner options"))
31+
}
2832
}
2933

34+
for (fullHelpOptions <- HelpTests.fullHelpVariants) {
35+
lazy val fullHelp = os.proc(TestUtil.cli, fullHelpOptions).call(check = false)
36+
lazy val fullHelpOutput = fullHelp.out.trim()
37+
val fullHelpOptionsString = fullHelpOptions.mkString(" ")
38+
test(s"$fullHelpOptionsString works correctly") {
39+
assert(
40+
fullHelp.exitCode == 0,
41+
clues(fullHelpOptions, fullHelp.out.text(), fullHelp.err.text(), fullHelp.exitCode)
42+
)
43+
expect(fullHelpOutput.contains("Usage:"))
44+
}
45+
test(s"$fullHelpOptionsString output includes legacy scala runner options") {
46+
expect(fullHelpOutput.contains("Legacy Scala runner options"))
47+
}
48+
}
3049
}
3150

3251
object HelpTests {
3352
val variants =
34-
Seq(Seq("help"), Seq("help", "-help"), Seq("help", "--help"), Seq("-help"), Seq("--help"))
53+
Seq(
54+
Seq("help"),
55+
Seq("help", "-help"),
56+
Seq("help", "--help"),
57+
Seq("-help"),
58+
Seq("--help")
59+
)
60+
val fullHelpVariants =
61+
Seq(
62+
Seq("help", "--full-help"),
63+
Seq("help", "-full-help"),
64+
Seq("help", "--help-full"),
65+
Seq("help", "-help-full"),
66+
Seq("--full-help"),
67+
Seq("-full-help"),
68+
Seq("-help-full")
69+
)
3570
}

0 commit comments

Comments
 (0)