Skip to content

Commit e1d3042

Browse files
authored
Merge pull request #1915 from Gedochao/specification-level-experimental
Fix handling for `experimental` features
2 parents f5872d9 + 5c44437 commit e1d3042

File tree

25 files changed

+119
-91
lines changed

25 files changed

+119
-91
lines changed

modules/build/src/main/scala/scala/build/preprocessing/DirectivesProcessor.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ object DirectivesProcessor {
3333
scopedDirective: ScopedDirective,
3434
logger: Logger
3535
) =
36-
if (!allowRestrictedFeatures && handler.isRestricted)
36+
if (!allowRestrictedFeatures && (handler.isRestricted || handler.isExperimental))
37+
val powerDirectiveType = if handler.isExperimental then "experimental" else "restricted"
3738
val msg =
38-
"""This directive is not supported.
39-
|Please run it with the `--power` flag or turn this flag on globally by running `config power true`.""".stripMargin
39+
s"""This directive is $powerDirectiveType.
40+
|Please run it with the '--power' flag or turn this flag on globally by running 'config power true'""".stripMargin
4041
Left(DirectiveErrors(
4142
::(msg, Nil),
4243
DirectiveUtil.positions(scopedDirective.directive.values, path)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ trait RestrictableCommand[T](implicit myParser: Parser[T]) {
1010

1111
final def isRestricted: Boolean = scalaSpecificationLevel == SpecificationLevel.RESTRICTED
1212

13+
final def isExperimental: Boolean = scalaSpecificationLevel == SpecificationLevel.EXPERIMENTAL
14+
1315
/** Is that command a MUST / SHOULD / NICE TO have for the Scala runner specification? */
1416
def scalaSpecificationLevel: SpecificationLevel
1517
// To reduce imports...

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/commands/ScalaCommand.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ abstract class ScalaCommand[T <: HasLoggingOptions](implicit myParser: Parser[T]
3838

3939
def sharedOptions(t: T): Option[SharedOptions] = // hello borked unused warning
4040
None
41-
override def hasFullHelp = true
42-
override def hidden = shouldExcludeInSip
43-
protected var argvOpt = Option.empty[Array[String]]
44-
private val shouldExcludeInSip = isRestricted && !ScalaCli.allowRestrictedFeatures
41+
override def hasFullHelp = true
42+
override def hidden = shouldExcludeInSip
43+
protected var argvOpt = Option.empty[Array[String]]
44+
private val shouldExcludeInSip =
45+
(isRestricted || isExperimental) && !ScalaCli.allowRestrictedFeatures
4546
override def setArgv(argv: Array[String]): Unit = {
4647
argvOpt = Some(argv)
4748
}
@@ -275,7 +276,9 @@ abstract class ScalaCommand[T <: HasLoggingOptions](implicit myParser: Parser[T]
275276

276277
override val messages: Help[T] =
277278
if (shouldExcludeInSip)
278-
Help[T](helpMessage = Some(HelpMessage(HelpMessages.restrictedCommandUsedInSip)))
279+
Help[T](helpMessage =
280+
Some(HelpMessage(HelpMessages.powerCommandUsedInSip(scalaSpecificationLevel)))
281+
)
279282
else help
280283

281284
/** @param options
@@ -307,7 +310,7 @@ abstract class ScalaCommand[T <: HasLoggingOptions](implicit myParser: Parser[T]
307310
*/
308311
final override def run(options: T, remainingArgs: RemainingArgs): Unit = {
309312
if (shouldExcludeInSip)
310-
System.err.println(HelpMessages.restrictedCommandUsedInSip)
313+
System.err.println(HelpMessages.powerCommandUsedInSip(scalaSpecificationLevel))
311314
sys.exit(1)
312315
CurrentParams.verbosity = options.logging.verbosity
313316
maybePrintWarnings(options)

modules/cli/src/main/scala/scala/cli/commands/export0/Export.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import scala.cli.util.ArgHelpers.*
2525
import scala.util.Using
2626

2727
object Export extends ScalaCommand[ExportOptions] {
28-
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.RESTRICTED
28+
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.EXPERIMENTAL
2929

3030
override def helpFormat: HelpFormat =
3131
super.helpFormat.withPrimaryGroup(HelpGroup.BuildToolExport)

modules/cli/src/main/scala/scala/cli/commands/github/SecretCreate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import scala.cli.util.ArgHelpers.*
2121

2222
object SecretCreate extends ScalaCommand[SecretCreateOptions] {
2323

24-
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.RESTRICTED
24+
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.EXPERIMENTAL
2525
override def helpFormat: HelpFormat = super.helpFormat.withPrimaryGroup(HelpGroup.Secret)
2626
override def names = List(
2727
List("github", "secret", "create"),

modules/cli/src/main/scala/scala/cli/commands/github/SecretList.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.cli.util.ArgHelpers.*
1717

1818
object SecretList extends ScalaCommand[SecretListOptions] {
1919

20-
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.RESTRICTED
20+
override def scalaSpecificationLevel: SpecificationLevel = SpecificationLevel.EXPERIMENTAL
2121

2222
override def helpFormat: HelpFormat = super.helpFormat.withPrimaryGroup(HelpGroup.Secret)
2323
override def names = List(

modules/cli/src/main/scala/scala/cli/commands/pgp/PgpCommand.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class PgpCommand[T](implicit myParser: Parser[T], help: Help[T])
1212
extends Command()(myParser, help)
1313
with CommandHelpers with RestrictableCommand[T] {
1414

15-
override def scalaSpecificationLevel = SpecificationLevel.RESTRICTED
15+
override def scalaSpecificationLevel = SpecificationLevel.EXPERIMENTAL
1616

1717
override def hidden = true
1818
}

modules/cli/src/main/scala/scala/cli/commands/pgp/PgpPull.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import scala.cli.commands.util.ScalaCliSttpBackend
1010
object PgpPull extends ScalaCommand[PgpPullOptions] {
1111

1212
override def hidden = true
13-
override def scalaSpecificationLevel = SpecificationLevel.RESTRICTED
13+
override def scalaSpecificationLevel = SpecificationLevel.EXPERIMENTAL
1414
override def names = List(
1515
List("pgp", "pull")
1616
)

modules/cli/src/main/scala/scala/cli/commands/pgp/PgpPush.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.cli.internal.PgpProxyMakerSubst
1212
object PgpPush extends ScalaCommand[PgpPushOptions] {
1313

1414
override def hidden = true
15-
override def scalaSpecificationLevel = SpecificationLevel.RESTRICTED
15+
override def scalaSpecificationLevel = SpecificationLevel.EXPERIMENTAL
1616
override def names = List(
1717
List("pgp", "push")
1818
)

0 commit comments

Comments
 (0)