Skip to content
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

Ensure external help options are mentioned in short help where available #2808

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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