Skip to content

Commit 30eeeb3

Browse files
authored
feat(pace-183): allow the option to specify an absolute path (#221)
1 parent d4dcc0c commit 30eeeb3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

dbt/src/main/kotlin/com/getstrm/pace/dbt/Main.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ package com.getstrm.pace.dbt
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import java.io.File
55
import java.io.FileNotFoundException
6+
import java.nio.file.Paths
67
import kotlin.system.exitProcess
78

8-
fun main() {
9+
fun main(args: Array<String>) {
10+
val basePath = if (args.isEmpty()) {
11+
Paths.get("").toAbsolutePath().toString()
12+
} else if (args.size == 1) {
13+
args[0]
14+
} else {
15+
println("Either provide 0 arguments or an absolute path to the dbt project directory.")
16+
exitProcess(1)
17+
}
18+
919
System.setProperty("org.jooq.no-logo", "true")
1020
System.setProperty("org.jooq.no-tips", "true")
1121

1222
// Note! Working dir when running this must be the root of the desired dbt project!
1323
try {
1424
val manifestJson =
15-
File("target/manifest.json").readText().let { ObjectMapper().readTree(it) }
25+
File("$basePath/target/manifest.json").readText().let { ObjectMapper().readTree(it) }
1626

1727
val dataPolicies = ManifestParser.createDataPolicies(manifestJson)
1828
dataPolicies.forEach { (policy, sourceModel, violations) ->
1929
if (violations.isEmpty()) {
20-
ModelWriter(policy, sourceModel).write()
30+
ModelWriter(policy, sourceModel, basePath).write()
2131
} else {
2232
println(
2333
"Skipping policy for source model ${sourceModel.originalFilePath} due to violations: $violations"

dbt/src/main/kotlin/com/getstrm/pace/dbt/ModelWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import build.buf.gen.getstrm.pace.api.entities.v1alpha.DataPolicy
44
import java.io.File
55
import org.jetbrains.annotations.VisibleForTesting
66

7-
class ModelWriter(private val policy: DataPolicy, private val sourceModel: DbtModel) {
7+
class ModelWriter(private val policy: DataPolicy, private val sourceModel: DbtModel, private val basePath: String) {
88

99
fun write() {
1010
// Todo: take global transforms into account
1111
val viewGenerator = ViewGeneratorFactory.create(policy, sourceModel)
1212
viewGenerator.toSelectStatement(inlineParameters = true).forEach { (target, query) ->
13-
val targetFilePath = targetFilePath(target)
13+
val targetFilePath = "$basePath/${targetFilePath(target)}"
1414
val file = File(targetFilePath)
1515
val header = ModelHeaderRenderer(sourceModel, target).render()
1616
file.writeText("$header\n$query\n")

0 commit comments

Comments
 (0)