Skip to content

Commit 6a6c6d9

Browse files
committed
Add more descriptive messages for using experimental & restricted options without the power mode enabled
1 parent beec474 commit 6a6c6d9

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import caseapp.core.parser.Parser
66
import caseapp.core.util.Formatter
77
import caseapp.core.{Arg, Error}
88

9+
import scala.cli.ScalaCli
910
import scala.cli.util.ArgHelpers.*
1011

1112
object RestrictedCommandsParser {
@@ -33,11 +34,13 @@ object RestrictedCommandsParser {
3334
nameFormatter: Formatter[Name]
3435
): Either[(Error, Arg, List[String]), Option[(D, Arg, List[String])]] =
3536
(parser.step(args, index, d, nameFormatter), args) match {
36-
case (Right(Some(_, arg, _)), passedOption :: _) if !arg.isSupported =>
37+
case (Right(Some(_, arg: Arg, _)), passedOption :: _) if !arg.isSupported =>
38+
val powerOptionType = if arg.isExperimental then "experimental" else "restricted"
3739
Left((
3840
Error.UnrecognizedArgument(
39-
s"""`$passedOption` option is not supported.
40-
|Please run it with the `--power` flag or turn this flag on globally by running `config power true`.""".stripMargin
41+
s"""The '$passedOption' option is $powerOptionType.
42+
|You can run it with the '--power' flag or turn the power mode on globally by running:
43+
| ${Console.BOLD}${ScalaCli.progName} config power true${Console.RESET}.""".stripMargin
4144
),
4245
arg,
4346
Nil

modules/cli/src/main/scala/scala/cli/util/ArgHelpers.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import scala.cli.commands.{SpecificationLevel, tags}
99

1010
object ArgHelpers {
1111
extension (arg: Arg) {
12-
def isExperimentalOrRestricted: Boolean =
13-
arg.tags.exists(_.name == tags.restricted) || arg.tags.exists(_.name == tags.experimental)
12+
private def hasTag(tag: String): Boolean = arg.tags.exists(_.name == tag)
13+
def isExperimental: Boolean = arg.hasTag(tags.experimental)
14+
def isRestricted: Boolean = arg.hasTag(tags.restricted)
15+
16+
def isExperimentalOrRestricted: Boolean = arg.isRestricted || arg.isExperimental
1417

1518
def isSupported: Boolean = allowRestrictedFeatures || !arg.isExperimentalOrRestricted
16-
def isImportant: Boolean = arg.tags.exists(_.name == tags.inShortHelp)
19+
def isImportant: Boolean = arg.hasTag(tags.inShortHelp)
1720

18-
def isMust: Boolean = arg.tags.exists(_.name == tags.must)
21+
def isMust: Boolean = arg.hasTag(tags.must)
1922

2023
def level: SpecificationLevel = arg.tags
2124
.flatMap(t => tags.levelFor(t.name))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SipScalaTests extends ScalaCliSuite {
7878
if (isRestricted) {
7979
expect(res.exitCode == 1)
8080
val output = res.out.text()
81-
expect(output.contains(s"option is not supported"))
81+
expect(output.contains(s"option is experimental"))
8282
expect(output.contains("--markdown"))
8383
}
8484
else expect(res.exitCode == 0)

0 commit comments

Comments
 (0)