Skip to content

Commit bbb9a71

Browse files
authored
Ensure external help options are mentioned in short help where available (#2808)
1 parent 594d5d8 commit bbb9a71

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import caseapp.core.help.{Help, HelpCompanion, RuntimeCommandsHelp}
55
import caseapp.core.parser.Parser
66

77
import scala.cli.commands.default.{DefaultOptions, LegacyScalaOptions}
8-
import scala.cli.commands.shared.{HasGlobalOptions, ScalaCliHelp}
8+
import scala.cli.commands.shared.{
9+
AllExternalHelpOptions,
10+
HasGlobalOptions,
11+
HelpGroupOptions,
12+
ScalaCliHelp
13+
}
914
import scala.cli.commands.util.HelpUtils.*
1015
import scala.cli.launcher.LauncherOptions
1116

@@ -25,6 +30,8 @@ abstract class ScalaCommandWithCustomHelp[T <: HasGlobalOptions](
2530
val helpString = actualHelp.help(helpFormat, showHidden)
2631
val launcherHelpString = launcherHelp.optionsHelp(helpFormat, showHidden)
2732
val legacyScalaHelpString = legacyScalaHelp.optionsHelp(helpFormat, showHidden)
33+
val allExternalHelp = HelpCompanion.deriveHelp[AllExternalHelpOptions]
34+
val allExternalHelpString = allExternalHelp.optionsHelp(helpFormat, showHidden)
2835
val legacyScalaHelpStringWithPadding =
2936
if legacyScalaHelpString.nonEmpty then
3037
s"""
@@ -34,6 +41,8 @@ abstract class ScalaCommandWithCustomHelp[T <: HasGlobalOptions](
3441
s"""$helpString
3542
|
3643
|$launcherHelpString
44+
|
45+
|$allExternalHelpString
3746
|$legacyScalaHelpStringWithPadding""".stripMargin
3847
}
3948

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package scala.cli.commands.shared
2+
3+
import caseapp.core.Scala3Helpers.*
4+
import caseapp.core.help.{Help, HelpFormat}
5+
import caseapp.{Help, *}
6+
import com.github.plokhotnyuk.jsoniter_scala.core.*
7+
import com.github.plokhotnyuk.jsoniter_scala.macros.*
8+
9+
@HelpMessage("Print help message")
10+
// this is an aggregate for all external and internal help options
11+
case class AllExternalHelpOptions(
12+
@Recurse
13+
scalacExtra: ScalacExtraOptions = ScalacExtraOptions(),
14+
@Recurse
15+
helpGroups: HelpGroupOptions = HelpGroupOptions()
16+
)
17+
18+
object AllExternalHelpOptions {
19+
implicit lazy val parser: Parser[AllExternalHelpOptions] = Parser.derive
20+
implicit lazy val help: Help[AllExternalHelpOptions] = Help.derive
21+
implicit lazy val jsonCodec: JsonValueCodec[AllExternalHelpOptions] = JsonCodecMaker.make
22+
}

modules/cli/src/main/scala/scala/cli/commands/shared/ScalacExtraOptions.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import caseapp.*
44
import com.github.plokhotnyuk.jsoniter_scala.core.*
55
import com.github.plokhotnyuk.jsoniter_scala.macros.*
66

7+
import scala.cli.commands.tags
8+
79
/** Scala CLI options which aren't strictly scalac options, but directly involve the Scala compiler
810
* in some way.
911
*/
@@ -12,11 +14,13 @@ final case class ScalacExtraOptions(
1214
@Group(HelpGroup.Scala.toString)
1315
@HelpMessage("Show help for scalac. This is an alias for --scalac-option -help")
1416
@Name("helpScalac")
17+
@Tag(tags.inShortHelp)
1518
scalacHelp: Boolean = false,
1619

1720
@Group(HelpGroup.Scala.toString)
1821
@HelpMessage("Turn verbosity on for scalac. This is an alias for --scalac-option -verbose")
1922
@Name("verboseScalac")
23+
@Tag(tags.inShortHelp)
2024
scalacVerbose: Boolean = false,
2125
)
2226
// format: on

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ class HelpTests extends ScalaCliSuite {
2929
test(s"$helpOptionsString output does not include legacy scala runner options") {
3030
expect(!helpOutput.contains("Legacy Scala runner options"))
3131
}
32+
33+
test(s"$helpOptionsString output includes external help options") {
34+
expect(helpOutput.contains("--scalac-help"))
35+
expect(helpOutput.contains("--help-js"))
36+
expect(helpOutput.contains("--help-native"))
37+
expect(helpOutput.contains("--help-doc"))
38+
expect(helpOutput.contains("--help-repl"))
39+
expect(helpOutput.contains("--help-fmt"))
40+
}
3241
}
3342

3443
for (fullHelpOptions <- HelpTests.fullHelpVariants) {

0 commit comments

Comments
 (0)