feat: Adds git client tests, restructures files.
Some checks failed
CI / macOS (debug, 16.1) (push) Has been cancelled
CI / macOS (release, 16.1) (push) Has been cancelled
CI / Ubuntu (push) Failing after 5s

This commit is contained in:
2024-12-24 14:42:28 -05:00
parent 8aa4b73cab
commit 1972260317
26 changed files with 454 additions and 397 deletions

View File

@@ -7,24 +7,8 @@ import Rainbow
struct GlobalOptions: ParsableArguments {
@Option(
name: .shortAndLong,
help: "Specify the path to a configuration file."
)
var configurationFile: String?
@OptionGroup var targetOptions: TargetOptions
@OptionGroup var semvarOptions: SemVarOptions
@Flag(
name: .long,
inversion: .prefixedNo,
help: """
Include the short commit sha in version or pre-release branch style output.
"""
)
var commitSha: Bool = true
@OptionGroup
var configOptions: ConfigurationOptions
@Option(
name: .customLong("git-directory"),
@@ -44,6 +28,37 @@ struct GlobalOptions: ParsableArguments {
)
var verbose: Int
@Argument(
help: """
Arguments / options used for custom pre-release, options / flags must proceed a '--' in
the command. These are ignored if the `--custom` flag is not set.
"""
)
var extraOptions: [String] = []
}
struct ConfigurationOptions: ParsableArguments {
@Option(
name: .shortAndLong,
help: "Specify the path to a configuration file.",
completion: .file(extensions: ["json"])
)
var configurationFile: String?
@OptionGroup var targetOptions: TargetOptions
@OptionGroup var semvarOptions: SemVarOptions
@Flag(
name: .long,
inversion: .prefixedNo,
help: """
Include the short commit sha in version or pre-release branch style output.
"""
)
var commitSha: Bool = true
}
struct TargetOptions: ParsableArguments {
@@ -67,8 +82,6 @@ struct TargetOptions: ParsableArguments {
}
// TODO: Need to be able to pass in arguments for custom command pre-release option.
struct PreReleaseOptions: ParsableArguments {
@Flag(
@@ -101,14 +114,13 @@ struct PreReleaseOptions: ParsableArguments {
)
var preReleasePrefix: String?
@Option(
@Flag(
name: .long,
help: """
Apply custom pre-release suffix, can also use branch or tag along with this
option as a prefix, used if branch is not set. (example: \"rc\")
Apply custom pre-release suffix, using extra options / arguments passed in after a '--'.
"""
)
var custom: String?
var customPreRelease: Bool = false
}
@@ -130,102 +142,3 @@ struct SemVarOptions: ParsableArguments {
@OptionGroup var preRelease: PreReleaseOptions
}
// TODO: Move these to global options.
extension CliClient.SharedOptions {
func run(_ keyPath: KeyPath<CliClient, @Sendable (Self) async throws -> String>) async throws {
try await withDependencies {
$0.fileClient = .liveValue
$0.gitClient = .liveValue
$0.cliClient = .liveValue
} operation: {
@Dependency(\.cliClient) var cliClient
let output = try await cliClient[keyPath: keyPath](self)
print(output)
}
}
func run<T>(
_ keyPath: KeyPath<CliClient, @Sendable (T, Self) async throws -> String>,
args: T
) async throws {
try await withDependencies {
$0.fileClient = .liveValue
$0.gitClient = .liveValue
$0.cliClient = .liveValue
} operation: {
@Dependency(\.cliClient) var cliClient
let output = try await cliClient[keyPath: keyPath](args, self)
print(output)
}
}
}
extension GlobalOptions {
func shared() throws -> CliClient.SharedOptions {
try .init(
allowPreReleaseTag: !semvarOptions.preRelease.disablePreRelease,
dryRun: dryRun,
gitDirectory: gitDirectory,
verbose: verbose,
target: targetOptions.configTarget(),
branch: .init(includeCommitSha: commitSha),
semvar: semvarOptions.configSemVarOptions(),
configurationFile: configurationFile
)
}
}
// MARK: - Helpers
private extension TargetOptions {
func configTarget() throws -> Configuration.Target? {
guard let path else {
guard let module else {
return nil
}
return .init(module: .init(module, fileName: fileName))
}
return .init(path: path)
}
}
extension PreReleaseOptions {
// FIX:
func configPreReleaseStrategy() throws -> Configuration.PreRelease? {
return nil
// guard let custom else {
// if useBranchAsPreRelease {
// return .branch()
// } else if useTagAsPreRelease {
// return .gitTag
// } else {
// return nil
// }
// }
//
// if useBranchAsPreRelease {
// return .customBranchPrefix(custom)
// } else if useTagAsPreRelease {
// return .customGitTagPrefix(custom)
// } else {
// return .custom(custom)
// }
}
}
extension SemVarOptions {
func configSemVarOptions() throws -> Configuration.SemVar {
try .init(
preRelease: preRelease.configPreReleaseStrategy(),
requireExistingFile: requireExistingFile,
requireExistingSemVar: requireExistingSemvar
)
}
}