Skip to content

Commit

Permalink
Ensure external help options are mentioned in short help where availa…
Browse files Browse the repository at this point in the history
…ble (#2808)
  • Loading branch information
Gedochao committed Mar 26, 2024
1 parent 594d5d8 commit bbb9a71
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Expand Up @@ -5,7 +5,12 @@ import caseapp.core.help.{Help, HelpCompanion, RuntimeCommandsHelp}
import caseapp.core.parser.Parser

import scala.cli.commands.default.{DefaultOptions, LegacyScalaOptions}
import scala.cli.commands.shared.{HasGlobalOptions, ScalaCliHelp}
import scala.cli.commands.shared.{
AllExternalHelpOptions,
HasGlobalOptions,
HelpGroupOptions,
ScalaCliHelp
}
import scala.cli.commands.util.HelpUtils.*
import scala.cli.launcher.LauncherOptions

Expand All @@ -25,6 +30,8 @@ abstract class ScalaCommandWithCustomHelp[T <: HasGlobalOptions](
val helpString = actualHelp.help(helpFormat, showHidden)
val launcherHelpString = launcherHelp.optionsHelp(helpFormat, showHidden)
val legacyScalaHelpString = legacyScalaHelp.optionsHelp(helpFormat, showHidden)
val allExternalHelp = HelpCompanion.deriveHelp[AllExternalHelpOptions]
val allExternalHelpString = allExternalHelp.optionsHelp(helpFormat, showHidden)
val legacyScalaHelpStringWithPadding =
if legacyScalaHelpString.nonEmpty then
s"""
Expand All @@ -34,6 +41,8 @@ abstract class ScalaCommandWithCustomHelp[T <: HasGlobalOptions](
s"""$helpString
|
|$launcherHelpString
|
|$allExternalHelpString
|$legacyScalaHelpStringWithPadding""".stripMargin
}

Expand Down
@@ -0,0 +1,22 @@
package scala.cli.commands.shared

import caseapp.core.Scala3Helpers.*
import caseapp.core.help.{Help, HelpFormat}
import caseapp.{Help, *}
import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

@HelpMessage("Print help message")
// this is an aggregate for all external and internal help options
case class AllExternalHelpOptions(
@Recurse
scalacExtra: ScalacExtraOptions = ScalacExtraOptions(),
@Recurse
helpGroups: HelpGroupOptions = HelpGroupOptions()
)

object AllExternalHelpOptions {
implicit lazy val parser: Parser[AllExternalHelpOptions] = Parser.derive
implicit lazy val help: Help[AllExternalHelpOptions] = Help.derive
implicit lazy val jsonCodec: JsonValueCodec[AllExternalHelpOptions] = JsonCodecMaker.make
}
Expand Up @@ -4,6 +4,8 @@ import caseapp.*
import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

import scala.cli.commands.tags

/** Scala CLI options which aren't strictly scalac options, but directly involve the Scala compiler
* in some way.
*/
Expand All @@ -12,11 +14,13 @@ final case class ScalacExtraOptions(
@Group(HelpGroup.Scala.toString)
@HelpMessage("Show help for scalac. This is an alias for --scalac-option -help")
@Name("helpScalac")
@Tag(tags.inShortHelp)
scalacHelp: Boolean = false,

@Group(HelpGroup.Scala.toString)
@HelpMessage("Turn verbosity on for scalac. This is an alias for --scalac-option -verbose")
@Name("verboseScalac")
@Tag(tags.inShortHelp)
scalacVerbose: Boolean = false,
)
// format: on
Expand Down
Expand Up @@ -29,6 +29,15 @@ class HelpTests extends ScalaCliSuite {
test(s"$helpOptionsString output does not include legacy scala runner options") {
expect(!helpOutput.contains("Legacy Scala runner options"))
}

test(s"$helpOptionsString output includes external help options") {
expect(helpOutput.contains("--scalac-help"))
expect(helpOutput.contains("--help-js"))
expect(helpOutput.contains("--help-native"))
expect(helpOutput.contains("--help-doc"))
expect(helpOutput.contains("--help-repl"))
expect(helpOutput.contains("--help-fmt"))
}
}

for (fullHelpOptions <- HelpTests.fullHelpVariants) {
Expand Down

0 comments on commit bbb9a71

Please sign in to comment.