Skip to content

Commit 7561c07

Browse files
committed
dependencyTree output path WIP
1 parent 001d519 commit 7561c07

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package net.virtualvoid.sbt.graph
1818

19+
import java.nio.file.{ Files, Path, Paths }
20+
1921
import net.virtualvoid.sbt.graph.GraphTransformations.reverseGraphStartingAt
2022
import net.virtualvoid.sbt.graph.backend.{ IvyReport, SbtUpdateReport }
2123
import net.virtualvoid.sbt.graph.model.{ FilterRule, ModuleGraph, ModuleId }
@@ -80,7 +82,17 @@ object DependencyGraphSettings {
8082
moduleGraph.value,
8183
filterRulesParser.parsed: _*
8284
),
83-
dependencyTree := streams.value.log.info(asciiTree.evaluated),
85+
dependencyTree := {
86+
dependencyTreeOutputPathParser.parsed match {
87+
case Some(path)
88+
val os = Files.newOutputStream(path)
89+
os.write(asciiTree.evaluated.getBytes)
90+
os.close()
91+
case _
92+
streams.value.log.info(asciiTree.evaluated)
93+
}
94+
95+
},
8496
dependencyGraphMLFile := { target.value / "dependencies-%s.graphml".format(config.toString) },
8597
dependencyGraphML := dependencyGraphMLTask.value,
8698
dependencyDotFile := { target.value / "dependencies-%s.dot".format(config.toString) },
@@ -174,27 +186,40 @@ object DependencyGraphSettings {
174186
}.mkString("\n\n")
175187
streams.log.info(output)
176188
}
177-
val shouldForceParser: State Parser[Boolean] = { (state: State)
178-
import sbt.complete.DefaultParsers._
179189

190+
import sbt.complete.DefaultParsers._
191+
192+
val shouldForceParser: State Parser[Boolean] = { (state: State)
180193
(Space ~> token("--force")).?.map(_.isDefined)
181194
}
182195

196+
val dependencyTreeOutputPathParser: State Parser[Option[Path]] = { (state: State)
197+
(
198+
Space ~
199+
(token("--out") | token("-o")) ~>
200+
StringBasic
201+
)
202+
.map(Paths.get(_))
203+
.?
204+
}
205+
206+
val filterRulesParser_ = {
207+
(Space ~> token(StringBasic, "filter")).*.map {
208+
_.map(FilterRule(_))
209+
}
210+
}
211+
183212
val filterRulesParser: Def.Initialize[State Parser[Seq[FilterRule]]] =
184213
resolvedScoped { ctx
185214
(state: State)
186-
import sbt.complete.DefaultParsers._
187-
(Space ~> token(StringBasic, "filter")).*.map {
188-
_.map(FilterRule(_))
189-
}
215+
filterRulesParser_
190216
}
191217

192218
val artifactIdParser: Def.Initialize[State Parser[ModuleId]] =
193219
resolvedScoped { ctx
194220
(state: State)
195221
val graph = loadFromContext(moduleGraphStore, ctx, state) getOrElse ModuleGraph(Nil, Nil)
196222

197-
import sbt.complete.DefaultParsers._
198223
graph
199224
.nodes
200225
.map(_.id)

0 commit comments

Comments
 (0)