feat: Updates logging configuration.
This commit is contained in:
@@ -4,8 +4,10 @@ import Foundation
|
||||
import ShellClient
|
||||
|
||||
struct BuildCommand: AsyncParsableCommand {
|
||||
static let commandName = "build"
|
||||
|
||||
static let configuration: CommandConfiguration = .init(
|
||||
commandName: "build",
|
||||
commandName: Self.commandName,
|
||||
abstract: "Used for the build with version plugin.",
|
||||
discussion: "This should generally not be interacted with directly, outside of the build plugin.",
|
||||
shouldDisplay: false
|
||||
@@ -14,6 +16,6 @@ struct BuildCommand: AsyncParsableCommand {
|
||||
@OptionGroup var globals: GlobalOptions
|
||||
|
||||
func run() async throws {
|
||||
try await globals.run(\.build)
|
||||
try await globals.run(\.build, command: Self.commandName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import Dependencies
|
||||
|
||||
struct BumpCommand: AsyncParsableCommand {
|
||||
|
||||
static let commandName = "bump"
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "bump",
|
||||
commandName: Self.commandName,
|
||||
abstract: "Bump version of a command-line tool."
|
||||
)
|
||||
|
||||
@@ -19,7 +21,7 @@ struct BumpCommand: AsyncParsableCommand {
|
||||
var bumpOption: CliClient.BumpOption = .patch
|
||||
|
||||
func run() async throws {
|
||||
try await globals.run(\.bump, args: bumpOption)
|
||||
try await globals.run(\.bump, command: Self.commandName, args: bumpOption)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ import Foundation
|
||||
import ShellClient
|
||||
|
||||
struct GenerateCommand: AsyncParsableCommand {
|
||||
static let commandName = "generate"
|
||||
|
||||
static let configuration: CommandConfiguration = .init(
|
||||
commandName: "generate",
|
||||
commandName: Self.commandName,
|
||||
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."
|
||||
)
|
||||
@@ -14,6 +16,6 @@ struct GenerateCommand: AsyncParsableCommand {
|
||||
@OptionGroup var globals: GlobalOptions
|
||||
|
||||
func run() async throws {
|
||||
try await globals.run(\.generate)
|
||||
try await globals.run(\.generate, command: Self.commandName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ struct UtilsCommand: AsyncParsableCommand {
|
||||
|
||||
extension UtilsCommand {
|
||||
struct DumpConfig: AsyncParsableCommand {
|
||||
static let commandName = "dump-config"
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "dump-config",
|
||||
commandName: Self.commandName,
|
||||
abstract: "Show the parsed configuration.",
|
||||
aliases: ["dc"]
|
||||
)
|
||||
@@ -27,7 +29,7 @@ extension UtilsCommand {
|
||||
@OptionGroup var globals: GlobalOptions
|
||||
|
||||
func run() async throws {
|
||||
let configuration = try await globals.runClient(\.parsedConfiguration)
|
||||
let configuration = try await globals.runClient(\.parsedConfiguration, command: Self.commandName)
|
||||
customDump(configuration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,45 +21,49 @@ func withSetupDependencies<T>(
|
||||
extension GlobalOptions {
|
||||
|
||||
func runClient<T>(
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (CliClient.SharedOptions) async throws -> T>
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (CliClient.SharedOptions) async throws -> T>,
|
||||
command: String
|
||||
) async throws -> T {
|
||||
try await withSetupDependencies {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
return try await cliClient[keyPath: keyPath](shared())
|
||||
return try await cliClient[keyPath: keyPath](shared(command: command))
|
||||
}
|
||||
}
|
||||
|
||||
func runClient<A, T>(
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (A, CliClient.SharedOptions) async throws -> T>,
|
||||
command: String,
|
||||
args: A
|
||||
) async throws -> T {
|
||||
try await withSetupDependencies {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
return try await cliClient[keyPath: keyPath](args, shared())
|
||||
return try await cliClient[keyPath: keyPath](args, shared(command: command))
|
||||
}
|
||||
}
|
||||
|
||||
func run(
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (CliClient.SharedOptions) async throws -> String>
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (CliClient.SharedOptions) async throws -> String>,
|
||||
command: String
|
||||
) async throws {
|
||||
let output = try await runClient(keyPath)
|
||||
let output = try await runClient(keyPath, command: command)
|
||||
print(output)
|
||||
}
|
||||
|
||||
func run<T>(
|
||||
_ keyPath: KeyPath<CliClient, @Sendable (T, CliClient.SharedOptions) async throws -> String>,
|
||||
command: String,
|
||||
args: T
|
||||
) async throws {
|
||||
let output = try await runClient(keyPath, args: args)
|
||||
let output = try await runClient(keyPath, command: command, args: args)
|
||||
print(output)
|
||||
}
|
||||
|
||||
func shared() throws -> CliClient.SharedOptions {
|
||||
func shared(command: String) throws -> CliClient.SharedOptions {
|
||||
try .init(
|
||||
allowPreReleaseTag: !configOptions.semvarOptions.preRelease.disablePreRelease,
|
||||
dryRun: dryRun,
|
||||
gitDirectory: gitDirectory,
|
||||
verbose: verbose,
|
||||
loggingOptions: .init(command: command, verbose: verbose),
|
||||
target: configOptions.target(),
|
||||
branch: .init(includeCommitSha: configOptions.commitSha),
|
||||
semvar: configOptions.semvarOptions(extraOptions: extraOptions),
|
||||
@@ -93,6 +97,8 @@ extension PreReleaseOptions {
|
||||
throw ExtraOptionsEmpty()
|
||||
}
|
||||
return .init(prefix: preReleasePrefix, strategy: .command(arguments: extraOptions))
|
||||
} else if let preReleasePrefix {
|
||||
return .init(prefix: preReleasePrefix, strategy: nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user