Skip to content

Commit

Permalink
[patch] defaulting working directory to PWD
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Sep 12, 2024
1 parent 3e069bb commit 918a1ba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -31,7 +35,7 @@ class CalculateVersion : CliktCommand() {
)

override fun run() {
TaggerCore(GitAdapter(dir))
TaggerCore(GitAdapter(workingDirectory))
.calculateNextVersion(
implicitPatch = implicitPatch,
versionRegex = versionRegex(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit 918a1ba

Please sign in to comment.