feat: Updates dependencies and cli commands to be async.
This commit is contained in:
@@ -4,7 +4,7 @@ import Foundation
|
||||
import ShellClient
|
||||
|
||||
extension CliVersionCommand {
|
||||
struct Build: ParsableCommand {
|
||||
struct Build: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration = .init(
|
||||
abstract: "Used for the build with version plugin.",
|
||||
discussion: "This should generally not be interacted with directly, outside of the build plugin."
|
||||
@@ -19,8 +19,8 @@ extension CliVersionCommand {
|
||||
var gitDirectory: String
|
||||
|
||||
// TODO: Use CliClient
|
||||
func run() throws {
|
||||
try withDependencies {
|
||||
func run() async throws {
|
||||
try await withDependencies {
|
||||
$0.logger.logLevel = .debug
|
||||
$0.fileClient = .liveValue
|
||||
$0.gitVersionClient = .liveValue
|
||||
@@ -37,12 +37,12 @@ extension CliVersionCommand {
|
||||
let fileString = fileUrl.fileString()
|
||||
logger.info("File Url: \(fileString)")
|
||||
|
||||
let currentVersion = try gitVersion.currentVersion(in: gitDirectory)
|
||||
let currentVersion = try await gitVersion.currentVersion(in: gitDirectory)
|
||||
|
||||
let fileContents = buildTemplate
|
||||
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
|
||||
|
||||
try fileClient.write(string: fileContents, to: fileUrl)
|
||||
try await fileClient.write(string: fileContents, to: fileUrl)
|
||||
logger.info("Updated version file: \(fileString)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ import ArgumentParser
|
||||
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,
|
||||
]
|
||||
)
|
||||
struct CliVersionCommand: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration = .init(
|
||||
commandName: "cli-version",
|
||||
version: VERSION ?? "0.0.0",
|
||||
subcommands: [
|
||||
Build.self,
|
||||
Generate.self,
|
||||
Update.self
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import Foundation
|
||||
import ShellClient
|
||||
|
||||
extension CliVersionCommand {
|
||||
struct Generate: ParsableCommand {
|
||||
struct Generate: AsyncParsableCommand {
|
||||
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.",
|
||||
@@ -15,7 +15,7 @@ extension CliVersionCommand {
|
||||
@OptionGroup var shared: SharedOptions
|
||||
|
||||
// TODO: Use CliClient
|
||||
func run() throws {
|
||||
func run() async throws {
|
||||
@Dependency(\.logger) var logger: Logger
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
|
||||
@@ -30,7 +30,7 @@ extension CliVersionCommand {
|
||||
}
|
||||
|
||||
if !shared.dryRun {
|
||||
try fileClient.write(string: optionalTemplate, to: fileUrl)
|
||||
try await fileClient.write(string: optionalTemplate, to: fileUrl)
|
||||
logger.info("Generated file at: \(fileString)")
|
||||
} else {
|
||||
logger.info("Would generate file at: \(fileString)")
|
||||
|
||||
@@ -6,7 +6,7 @@ import ShellClient
|
||||
|
||||
extension CliVersionCommand {
|
||||
|
||||
struct Update: ParsableCommand {
|
||||
struct Update: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration = .init(
|
||||
abstract: "Updates a version string to the git tag or git sha.",
|
||||
discussion: "This command can be interacted with directly outside of the plugin context."
|
||||
@@ -21,17 +21,17 @@ extension CliVersionCommand {
|
||||
var gitDirectory: String?
|
||||
|
||||
// TODO: Use CliClient
|
||||
func run() throws {
|
||||
try withDependencies {
|
||||
func run() async throws {
|
||||
try await withDependencies {
|
||||
$0.logger.logLevel = shared.verbose ? .debug : .info
|
||||
$0.fileClient = .liveValue
|
||||
$0.gitVersionClient = .liveValue
|
||||
$0.shellClient = .liveValue
|
||||
$0.asyncShellClient = .liveValue
|
||||
} operation: {
|
||||
@Dependency(\.gitVersionClient) var gitVersion
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
@Dependency(\.logger) var logger
|
||||
@Dependency(\.shellClient) var shell
|
||||
@Dependency(\.asyncShellClient) var shell
|
||||
|
||||
let targetUrl = parseTarget(shared.target)
|
||||
let fileUrl = targetUrl
|
||||
@@ -39,13 +39,13 @@ extension CliVersionCommand {
|
||||
|
||||
let fileString = fileUrl.fileString()
|
||||
|
||||
let currentVersion = try gitVersion.currentVersion(in: gitDirectory)
|
||||
let currentVersion = try await gitVersion.currentVersion(in: gitDirectory)
|
||||
|
||||
let fileContents = optionalTemplate
|
||||
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
|
||||
|
||||
if !shared.dryRun {
|
||||
try fileClient.write(string: fileContents, to: fileUrl)
|
||||
try await fileClient.write(string: fileContents, to: fileUrl)
|
||||
logger.info("Updated version file: \(fileString)")
|
||||
} else {
|
||||
logger.info("Would update file contents to:")
|
||||
|
||||
Reference in New Issue
Block a user