feat: Begins update for more modern swift-dependencies implementation.

This commit is contained in:
2024-12-20 12:54:10 -05:00
parent 1885a90f62
commit 847ddbc7b5
19 changed files with 439 additions and 130 deletions

View File

@@ -1,6 +1,6 @@
import ArgumentParser
import Foundation
import CliVersion
import Foundation
import ShellClient
extension CliVersionCommand {
@@ -9,15 +9,16 @@ extension CliVersionCommand {
abstract: "Used for the build with version plugin.",
discussion: "This should generally not be interacted with directly, outside of the build plugin."
)
@OptionGroup var shared: SharedOptions
@Option(
name: .customLong("git-directory"),
help: "The git directory for the version."
)
var gitDirectory: String
// TODO: Use CliClient
func run() throws {
try withDependencies {
$0.logger.logLevel = .debug
@@ -29,10 +30,10 @@ extension CliVersionCommand {
@Dependency(\.logger) var logger: Logger
logger.info("Building with git-directory: \(gitDirectory)")
let fileUrl = URL(fileURLWithPath: shared.target)
.appendingPathComponent(shared.fileName)
let fileString = fileUrl.fileString()
logger.info("File Url: \(fileString)")
@@ -40,11 +41,10 @@ extension CliVersionCommand {
let fileContents = buildTemplate
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
try fileClient.write(string: fileContents, to: fileUrl)
logger.info("Updated version file: \(fileString)")
}
}
}
}

View File

@@ -3,15 +3,13 @@ import Foundation
@main
struct CliVersionCommand: ParsableCommand {
static var configuration: CommandConfiguration = .init(
commandName: "cli-version",
version: VERSION ?? "0.0.0",
subcommands: [
Build.self,
Generate.self,
Update.self
]
)
static var configuration: CommandConfiguration = .init(
commandName: "cli-version",
version: VERSION ?? "0.0.0",
subcommands: [
Build.self,
Generate.self,
Update.self,
]
)
}

View File

@@ -1,11 +1,10 @@
import ArgumentParser
import CliVersion
import Dependencies
import Foundation
import CliVersion
import ShellClient
extension CliVersionCommand {
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.",
@@ -15,6 +14,7 @@ extension CliVersionCommand {
@OptionGroup var shared: SharedOptions
// TODO: Use CliClient
func run() throws {
@Dependency(\.logger) var logger: Logger
@Dependency(\.fileClient) var fileClient
@@ -35,12 +35,10 @@ extension CliVersionCommand {
} else {
logger.info("Would generate file at: \(fileString)")
}
}
}
}
fileprivate enum GenerationError: Error {
private enum GenerationError: Error {
case fileExists(path: String)
}

View File

@@ -15,7 +15,7 @@ func parseTarget(_ target: String) -> URL {
extension URL {
func fileString() -> String {
self.absoluteString
absoluteString
.replacingOccurrences(of: "file://", with: "")
}
}
@@ -32,6 +32,7 @@ let VERSION: String = nil
"""
// TODO: Use Int for `verbose`.
struct SharedOptions: ParsableArguments {
@Argument(help: "The target for the version file.")

View File

@@ -1,6 +1,7 @@
import ArgumentParser
import Foundation
import CliVersion
import Dependencies
import Foundation
import ShellClient
extension CliVersionCommand {
@@ -17,8 +18,9 @@ extension CliVersionCommand {
name: .customLong("git-directory"),
help: "The git directory for the version."
)
var gitDirectory: String? = nil
var gitDirectory: String?
// TODO: Use CliClient
func run() throws {
try withDependencies {
$0.logger.logLevel = shared.verbose ? .debug : .info
@@ -54,6 +56,6 @@ extension CliVersionCommand {
}
}
fileprivate enum UpdateError: Error {
private enum UpdateError: Error {
case versionFileDoesNotExist(path: String)
}