This commit is contained in:
2023-03-15 09:46:51 -04:00
parent 3dc5d8f524
commit 8ebfa1975a
13 changed files with 194 additions and 140 deletions

View File

@@ -38,7 +38,7 @@ extension GitVersionCommand {
let currentVersion = try gitVersion.currentVersion(in: gitDirectory)
let fileContents = template
let fileContents = buildTemplate
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
try fileClient.write(string: fileContents, to: fileUrl)

View File

@@ -9,7 +9,8 @@ extension GitVersionCommand {
struct Generate: ParsableCommand {
static var configuration: CommandConfiguration = .init(
abstract: "Generates a version file in a command line tool that can be set via the git tag or git sha.",
discussion: "This command can be interacted with directly, outside of the plugin usage context."
discussion: "This command can be interacted with directly, outside of the plugin usage context.",
version: VERSION ?? "0.0.0"
)
@OptionGroup var shared: SharedOptions
@@ -29,7 +30,7 @@ extension GitVersionCommand {
}
if !shared.dryRun {
try fileClient.write(string: template, to: fileUrl)
try fileClient.write(string: optionalTemplate, to: fileUrl)
logger.info("Generated file at: \(fileString)")
} else {
logger.info("Would generate file at: \(fileString)")

View File

@@ -20,12 +20,18 @@ extension URL {
}
}
let template = """
let optionalTemplate = """
// Do not set this variable, it is set during the build process.
let VERSION: String? = nil
"""
let buildTemplate = """
// Do not set this variable, it is set during the build process.
let VERSION: String = nil
"""
struct SharedOptions: ParsableArguments {
@Argument(help: "The target for the version file.")

View File

@@ -39,7 +39,7 @@ extension GitVersionCommand {
let currentVersion = try gitVersion.currentVersion(in: gitDirectory)
let fileContents = template
let fileContents = optionalTemplate
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
if !shared.dryRun {

View File

@@ -1,2 +1,2 @@
// Do not set this variable, it is set during the build process.
let VERSION: String? = nil
let VERSION: String? = "main 3dc5d8f"