-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anna-skrodzka
committed
Nov 14, 2024
1 parent
9a2d1c6
commit 950aced
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//rules:scala.bzl", "scala_binary") | ||
|
||
scala_binary( | ||
name = "scalafmt", | ||
args = [ | ||
"--toolchain=", | ||
"--opts=:--verbose:--config", | ||
], | ||
main_class = "rules_scala3.scalafix.src.Main", | ||
scala = "//scala:bootstrap_3", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@rules_scala3//3rdparty/jvm/com/github/scopt", | ||
], | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package rules_scala3.scalafix.src | ||
|
||
import scopt.OParser | ||
|
||
case class ArgsConfig( | ||
toolchain: Option[String] = None, | ||
scalafixOpts: Option[String] = None, | ||
targets: Seq[String] = Seq.empty, | ||
excludedTargets: Seq[String] = Seq.empty | ||
) | ||
|
||
object ArgsConfig: | ||
private val builder = OParser.builder[ArgsConfig] | ||
import builder.* | ||
|
||
private val parser = OParser.sequence( | ||
programName("scalafix-runner"), | ||
head("scalafix-runner", "1.0"), | ||
|
||
help('h', "help").text("Displays this usage text"), | ||
|
||
opt[String]('t', "toolchain") | ||
.required() | ||
.action((value, config) => config.copy(toolchain = Some(value))) | ||
.text("Required. Specifies the toolchain with which targets will be built"), | ||
|
||
opt[String]('o', "opts") | ||
.action((value, config) => config.copy(scalafixOpts = Some(value))) | ||
.text("Options passed to scalafix as a colon-separated string (e.g., :--verbose:--config)"), | ||
|
||
arg[String]("<target>...") | ||
.unbounded() | ||
.optional() | ||
.action((target, config) => config.copy(targets = config.targets :+ target)) | ||
.text("Specifies the Bazel targets to be included"), | ||
|
||
checkConfig { config => | ||
val (excluded, included) = config.targets.partition(_.startsWith("-")) | ||
Right(config.copy(excludedTargets = excluded.map(_.drop(1)), targets = included)) | ||
} | ||
) | ||
|
||
def parse(args: Seq[String]): Option[ArgsConfig] = OParser.parse(parser, args, ArgsConfig()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package rules_scala3.scalafix.src | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = | ||
given Vars = ArgsConfig(args.toIndexedSeq).getOrElse(sys.exit(2)) |