Skip to content

Commit

Permalink
Merge pull request #1835 from lwronski/config-power
Browse files Browse the repository at this point in the history
Add config to turn on globally power
  • Loading branch information
lwronski authored Feb 10, 2023
2 parents 0f508d9 + 2ee2012 commit ddc7999
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ object DirectivesProcessor {
) =
if (!allowRestrictedFeatures && handler.isRestricted)
val msg =
"This directive is not supported with 'scala' command. Please run it with `scala-cli` command or with `--power` flag."
"""This directive is not supported with 'scala' command.
|Please run it with `scala-cli` command or with `--power` flag or turn on this flag globally running command `config power true`.""".stripMargin
Left(DirectiveErrors(
::(msg, Nil),
DirectiveUtil.positions(scopedDirective.directive.values, path)
Expand Down
12 changes: 11 additions & 1 deletion modules/cli/src/main/scala/scala/cli/ScalaCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.Locale

import scala.build.Directories
import scala.build.blooprifle.FailedToStartServerException
import scala.build.internal.Constants
import scala.cli.config.{ConfigDb, Keys}
import scala.cli.internal.Argv0
import scala.cli.launcher.{LauncherCli, LauncherOptions}
import scala.cli.publish.BouncycastleSignerMaker
Expand Down Expand Up @@ -40,7 +42,15 @@ object ScalaCli {
baseProgName.endsWith(s"${File.separator}.$name.aux") // cs install binaries under .app-name.aux
}

private var isSipScala = checkName("scala") || checkName("scala-cli-sip")
private var isSipScala = {
val isSipConfigDb = for {
configDb <- ConfigDb.open(Directories.directories.dbPath.toNIO).toOption
powerEntry <- configDb.get(Keys.power).toOption
power <- powerEntry
} yield !power

isSipConfigDb.getOrElse(checkName("scala") || checkName("scala-cli-sip"))
}
def allowRestrictedFeatures = !isSipScala
def fullRunnerName = if (isSipScala) "Scala code runner" else "Scala CLI"
def baseRunnerName = if (isSipScala) "scala" else "scala-cli"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ object RestrictedCommandsParser {
case Right(Some(_, arg, _)) if !arg.isSupported =>
Left((
Error.UnrecognizedArgument(
s"`${args(index)}` option is not supported in `scala` command.\n Please run it with `scala-cli` command or with `--power` flag."
s"""`${args(index)}` option is not supported in `scala` command.
|Please run it with `scala-cli` command or with `--power` flag or turn on this flag globally running command `config power true`.""".stripMargin
),
arg,
Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.cli.config.{

object Config extends ScalaCommand[ConfigOptions] {
override def hidden = true
override def scalaSpecificationLevel = SpecificationLevel.RESTRICTED
override def scalaSpecificationLevel = SpecificationLevel.MUST

override def runCommand(options: ConfigOptions, args: RemainingArgs, logger: Logger): Unit = {
val directories = Directories.directories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.cli.commands.shared.{
LoggingOptions,
SharedJvmOptions
}
import scala.cli.commands.tags

// format: off
final case class ConfigOptions(
Expand All @@ -19,38 +20,47 @@ final case class ConfigOptions(
@Recurse
jvm: SharedJvmOptions = SharedJvmOptions(),
@Recurse
@Tag(tags.restricted)
scalaSigning: PgpScalaSigningOptions = PgpScalaSigningOptions(),
@Group("Config")
@HelpMessage("Dump config DB as JSON")
@Hidden
dump: Boolean = false,
@Group("Config")
@HelpMessage("Create PGP key in config")
@Tag(tags.restricted)
createPgpKey: Boolean = false,
@Group("Config")
@HelpMessage("Email to use to create PGP key in config")
@Tag(tags.restricted)
email: Option[String] = None,
@Group("Config")
@HelpMessage("If the entry is a password, print the password value rather than how to get the password")
@Tag(tags.restricted)
password: Boolean = false,
@Group("Config")
@HelpMessage("If the entry is a password, save the password value rather than how to get the password")
@Tag(tags.restricted)
passwordValue: Boolean = false,
@Group("Config")
@HelpMessage("Remove an entry from config")
@ExtraName("remove")
unset: Boolean = false,
@Group("Config")
@HelpMessage("For repository.credentials and publish.credentials, whether these credentials should be HTTPS only (default: true)")
@Tag(tags.restricted)
httpsOnly: Option[Boolean] = None,
@Group("Config")
@HelpMessage("For repository.credentials, whether to use these credentials automatically based on the host")
@Tag(tags.restricted)
matchHost: Option[Boolean] = None,
@Group("Config")
@HelpMessage("For repository.credentials, whether to use these credentials are optional")
@Tag(tags.restricted)
optional: Option[Boolean] = None,
@Group("Config")
@HelpMessage("For repository.credentials, whether to use these credentials should be passed upon redirection")
@Tag(tags.restricted)
passOnRedirect: Option[Boolean] = None
) extends HasLoggingOptions
// format: on
Expand Down
5 changes: 3 additions & 2 deletions modules/config/src/main/scala/scala/cli/config/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ object Keys {
val pgpSecretKeyPassword = new Key.PasswordEntry(Seq("pgp"), "secret-key-password")
val pgpPublicKey = new Key.PasswordEntry(Seq("pgp"), "public-key")

val actions = new Key.BooleanEntry(Seq.empty, "actions")

val actions = new Key.BooleanEntry(Seq.empty, "actions")
val interactive = new Key.BooleanEntry(Seq.empty, "interactive")
val power = new Key.BooleanEntry(Seq.empty, "power")

val suppressDirectivesInMultipleFilesWarning =
new Key.BooleanEntry(Seq("suppress-warning"), "directives-in-multiple-files")
Expand Down Expand Up @@ -47,6 +47,7 @@ object Keys {
pgpPublicKey,
pgpSecretKey,
pgpSecretKeyPassword,
power,
proxyAddress,
proxyPassword,
proxyUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,28 @@ class SipScalaTests extends ScalaCliSuite {
testReplHelpOutput(binaryName)
}
}

test("power config turn on power features") {
TestInputs.empty.fromRoot { root =>
val homeEnv = Map("SCALA_CLI_HOME" -> root.toString())
// disable power features
os.proc(TestUtil.cli, "config", "power", "false").call(cwd = root, env = homeEnv).out.trim()
val output = os.proc(TestUtil.cli, "package").call(
cwd = root,
check = false,
mergeErrIntoOut = true,
env = homeEnv
).out.text().trim
expect(output.contains("package: not found"))
// enable power features
os.proc(TestUtil.cli, "config", "power", "true").call(cwd = root, env = homeEnv).out.trim()
val powerOutput = os.proc(TestUtil.cli, "package").call(
cwd = root,
check = false,
mergeErrIntoOut = true,
env = homeEnv
).out.text().trim
expect(powerOutput.contains("No inputs provided"))
}
}
}
56 changes: 50 additions & 6 deletions website/docs/reference/scala-command/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Compile test scope

Available in commands:

[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test)
[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -328,7 +328,7 @@ Pass scalafmt version before running it (3.6.1 by default). If passed, this over

Available in commands:

[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)
[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -482,7 +482,7 @@ Add java properties. Note that options equal `-Dproperty=value` are assumed to b

Available in commands:

[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test)
[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -542,7 +542,7 @@ Port for BSP debugging

Available in commands:

[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)
[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -1152,7 +1152,7 @@ A github token used to access GitHub. Not needed in most cases.

Available in commands:

[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)
[`bsp`](./commands.md#bsp), [`clean`](./commands.md#clean), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`help`](./commands.md#help), [`install completions` , `install-completions`](./commands.md#install-completions), [`install-home`](./commands.md#install-home), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall), [`uninstall completions` , `uninstall-completions`](./commands.md#uninstall-completions), [`update`](./commands.md#update), [`version`](./commands.md#version)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -1277,11 +1277,33 @@ Aliases: `--name`

Name of BSP

### Config options

Available in commands:

[`config`](./commands.md#config)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

### `--dump`

`IMPLEMENTATION specific` per Scala Runner specification

Dump config DB as JSON

### `--unset`

Aliases: `--remove`

`IMPLEMENTATION specific` per Scala Runner specification

Remove an entry from config

### Coursier options

Available in commands:

[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall)
[`bsp`](./commands.md#bsp), [`compile`](./commands.md#compile), [`config`](./commands.md#config), [`doc`](./commands.md#doc), [`fmt` , `format` , `scalafmt`](./commands.md#fmt), [`repl` , `console`](./commands.md#repl), [`run`](./commands.md#run), [`setup-ide`](./commands.md#setup-ide), [`shebang`](./commands.md#shebang), [`test`](./commands.md#test), [`uninstall`](./commands.md#uninstall)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

Expand Down Expand Up @@ -1357,6 +1379,28 @@ Print the update to `env` variable

Binary directory

### Pgp scala signing options

Available in commands:

[`config`](./commands.md#config)

<!-- Automatically generated, DO NOT EDIT MANUALLY -->

### `--signing-cli-version`

`IMPLEMENTATION specific` per Scala Runner specification

### `--signing-cli-java-arg`

`IMPLEMENTATION specific` per Scala Runner specification

### `--force-jvm-signing-cli`

`IMPLEMENTATION specific` per Scala Runner specification

Whether to run the Scala Signing CLI on the JVM or using a native executable

### Repl options

Available in commands:
Expand Down
4 changes: 4 additions & 0 deletions website/docs/reference/scala-command/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Compile Scala code

Accepts option groups: [compilation server](./cli-options.md#compilation-server-options), [compile](./cli-options.md#compile-options), [coursier](./cli-options.md#coursier-options), [cross](./cli-options.md#cross-options), [debug](./cli-options.md#debug-options), [dependency](./cli-options.md#dependency-options), [help group](./cli-options.md#help-group-options), [input](./cli-options.md#input-options), [jvm](./cli-options.md#jvm-options), [logging](./cli-options.md#logging-options), [markdown](./cli-options.md#markdown-options), [python](./cli-options.md#python-options), [Scala.js](./cli-options.md#scalajs-options), [Scala Native](./cli-options.md#scala-native-options), [scalac](./cli-options.md#scalac-options), [scalac extra](./cli-options.md#scalac-extra-options), [shared](./cli-options.md#shared-options), [snippet](./cli-options.md#snippet-options), [suppress warning](./cli-options.md#suppress-warning-options), [verbosity](./cli-options.md#verbosity-options), [watch](./cli-options.md#watch-options), [workspace](./cli-options.md#workspace-options)

### config

Accepts option groups: [config](./cli-options.md#config-options), [coursier](./cli-options.md#coursier-options), [debug](./cli-options.md#debug-options), [jvm](./cli-options.md#jvm-options), [logging](./cli-options.md#logging-options), [pgp scala signing](./cli-options.md#pgp-scala-signing-options), [verbosity](./cli-options.md#verbosity-options)

### doc

Generate Scaladoc documentation
Expand Down
Loading

0 comments on commit ddc7999

Please sign in to comment.