Skip to content

Commit

Permalink
use same interface for normal and compilation-less, informational ones
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Apr 17, 2024
1 parent 7392720 commit c28d835
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -416,25 +416,32 @@ object ScalafixPlugin extends AutoPlugin {
(ScalafixConfig / externalDependencyClasspath).value
.flatMap(_.get(moduleID.key))

if (shellArgs.rules.isEmpty && shellArgs.extra == List("--help")) {
scalafixHelp
val allResolvers =
((ThisBuild / scalafixResolvers).value ++ (ThisBuild / scalafixSbtResolversAsCoursierRepositories).value).distinct
val (shell, baseInterface) = scalafixArgsFromShell(
shellArgs,
projectDepsExternal,
projectDepsInternal,
scalafixScalaBinaryVersion.value,
scalafixDependencies.value,
allResolvers,
(ThisBuild / scalafixCallback).value,
scalafixInterfaceCache.value
)

val informationalInvocation = shellArgs.extra
.intersect(List("--help", "-h", "--version", "-v"))
.nonEmpty

if (informationalInvocation) {
Def.task[Unit](
baseInterface.withArgs(Arg.ParsedArgs(shell.extra)).run()
)
} else {
val scalafixConf = (config / scalafixConfig).value.map(_.toPath)
val allResolvers =
((ThisBuild / scalafixResolvers).value ++ (ThisBuild / scalafixSbtResolversAsCoursierRepositories).value).distinct
val (shell, mainInterface0) = scalafixArgsFromShell(
shellArgs,
projectDepsExternal,
projectDepsInternal,
scalafixScalaBinaryVersion.value,
scalafixDependencies.value,
allResolvers,
(ThisBuild / scalafixCallback).value,
scalafixInterfaceCache.value
)
val maybeNoCache =
if (shell.noCache || !scalafixCaching.value) Seq(Arg.NoCache) else Nil
val mainInterface = mainInterface0
val mainInterface = baseInterface
.withArgs(maybeNoCache: _*)
.withArgs(
Arg.PrintStream(errorLogger),
Expand All @@ -457,25 +464,6 @@ object ScalafixPlugin extends AutoPlugin {
task.tag(Scalafix)
}

private def scalafixHelp: Def.Initialize[Task[Unit]] =
Def.task {
val allResolvers =
((ThisBuild / scalafixResolvers).value ++ (ThisBuild / scalafixSbtResolversAsCoursierRepositories).value).distinct
ScalafixInterface
.provider(
cache = scalafixInterfaceCache.value,
scalafixScalaBinaryVersion = scalafixScalaBinaryVersion.value,
scalafixDependencies = scalafixDependencies.value,
scalafixResolvers = allResolvers,
maybeToolClasspath = None,
logger = ScalafixInterface.defaultLogger,
callback = (ThisBuild / scalafixCallback).value
)()
.withArgs(Arg.ParsedArgs(List("--help")))
.run()
()
}

private def scalafixSyntactic(
mainInterface: ScalafixInterface,
shellArgs: ShellArgs,
Expand Down

0 comments on commit c28d835

Please sign in to comment.