From 918a1ba5d8665eddb943d0b3703890d43f0f3d74 Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Thu, 12 Sep 2024 08:57:10 -0400 Subject: [PATCH] [patch] defaulting working directory to PWD --- .../com/zegreatrob/tools/tagger/cli/CalculateVersion.kt | 8 ++++++-- .../kotlin/com/zegreatrob/tools/tagger/cli/Tag.kt | 7 +++++-- .../tagger/cli/CalculateVersionCommandConfigFileTest.kt | 2 -- .../tools/tagger/cli/TagCommandConfigFileTest.kt | 3 --- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersion.kt b/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersion.kt index cc8a36c2..5398a530 100644 --- a/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersion.kt +++ b/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersion.kt @@ -1,8 +1,10 @@ package com.zegreatrob.tools.tagger.cli import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.CliktError import com.github.ajalt.clikt.core.context import com.github.ajalt.clikt.parameters.arguments.argument +import com.github.ajalt.clikt.parameters.arguments.optional import com.github.ajalt.clikt.parameters.options.check import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option @@ -18,7 +20,9 @@ class CalculateVersion : CliktCommand() { context { valueSources(ConfigFileSource(envvarReader)) } } - private val dir by argument("git-repo") + private val gitRepoArgument by argument("git-repo").optional() + private val gitRepoOption by option("--git-repo", envvar = "PWD") + private val workingDirectory get() = gitRepoArgument ?: gitRepoOption ?: throw CliktError("No target directory") private val implicitPatch by option().boolean().default(true) private val releaseBranch by option() private val majorRegex by option().default(VersionRegex.Defaults.major.pattern) @@ -31,7 +35,7 @@ class CalculateVersion : CliktCommand() { ) override fun run() { - TaggerCore(GitAdapter(dir)) + TaggerCore(GitAdapter(workingDirectory)) .calculateNextVersion( implicitPatch = implicitPatch, versionRegex = versionRegex(), diff --git a/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/Tag.kt b/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/Tag.kt index c863be84..d23585b0 100644 --- a/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/Tag.kt +++ b/tools/tagger-cli/src/commonMain/kotlin/com/zegreatrob/tools/tagger/cli/Tag.kt @@ -4,6 +4,7 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.CliktError import com.github.ajalt.clikt.core.context import com.github.ajalt.clikt.parameters.arguments.argument +import com.github.ajalt.clikt.parameters.arguments.optional import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required @@ -19,14 +20,16 @@ class Tag : CliktCommand() { context { valueSources(ConfigFileSource(envvarReader)) } } - private val dir by argument("git-repo") + private val gitRepoArgument by argument("git-repo").optional() + private val gitRepoOption by option("--git-repo", envvar = "PWD") + private val workingDirectory get() = gitRepoArgument ?: gitRepoOption ?: throw CliktError("No target directory") private val releaseBranch by option().required() private val version: String by option().required() private val userName: String? by option() private val userEmail: String? by option() private val warningsAsErrors by option().boolean().default(false) override fun run() { - TaggerCore(GitAdapter(dir)) + TaggerCore(GitAdapter(workingDirectory)) .tag(version, releaseBranch, userName, userEmail) .let { when (it) { diff --git a/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersionCommandConfigFileTest.kt b/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersionCommandConfigFileTest.kt index bf3d9bba..df702c45 100644 --- a/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersionCommandConfigFileTest.kt +++ b/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/CalculateVersionCommandConfigFileTest.kt @@ -25,7 +25,6 @@ class CalculateVersionCommandConfigFileTest : CalculateVersionTestSpec { } override fun configureWithDefaults() { - arguments += projectDir.absolutePath val config = TaggerConfig(releaseBranch = "master") Json.encodeToStream(config, File(projectDir, ".tagger").outputStream()) } @@ -45,7 +44,6 @@ class CalculateVersionCommandConfigFileTest : CalculateVersionTestSpec { minorRegex?.let { config = config.copy(minorRegex = minorRegex) } patchRegex?.let { config = config.copy(patchRegex = patchRegex) } noneRegex?.let { config = config.copy(noneRegex = noneRegex) } - arguments += projectDir.absolutePath config = config.copy(releaseBranch = "master") Json.encodeToStream(config, File(projectDir, ".tagger").outputStream()) } diff --git a/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/TagCommandConfigFileTest.kt b/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/TagCommandConfigFileTest.kt index 242768a7..121b63c7 100644 --- a/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/TagCommandConfigFileTest.kt +++ b/tools/tagger-cli/src/jvmTest/kotlin/com/zegreatrob/tools/tagger/cli/TagCommandConfigFileTest.kt @@ -28,7 +28,6 @@ class TagCommandConfigFileTest : TagTestSpec { override fun configureWithDefaults() { val config = TaggerConfig(releaseBranch = "master") Json.encodeToStream(config, File(projectDir, ".tagger").outputStream()) - arguments += projectDir.absolutePath } override fun configureWithOverrides( @@ -43,8 +42,6 @@ class TagCommandConfigFileTest : TagTestSpec { userEmail?.let { config = config.copy(userEmail = userEmail) } warningsAsErrors?.let { config = config.copy(warningsAsErrors = warningsAsErrors) } Json.encodeToStream(config, File(projectDir, ".tagger").outputStream()) - - arguments += projectDir.absolutePath } override fun execute(version: String): TestResult {