feat: Commit pre integrating configuration client into cli-client.
This commit is contained in:
@@ -9,7 +9,8 @@ struct CliVersionCommand: AsyncParsableCommand {
|
||||
subcommands: [
|
||||
Build.self,
|
||||
Bump.self,
|
||||
Generate.self
|
||||
Generate.self,
|
||||
UtilsCommand.self
|
||||
],
|
||||
defaultSubcommand: Bump.self
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import ArgumentParser
|
||||
@_spi(Internal) import CliClient
|
||||
import ConfigurationClient
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import Rainbow
|
||||
@@ -173,6 +174,16 @@ private extension TargetOptions {
|
||||
}
|
||||
|
||||
struct InvalidTargetOption: Error {}
|
||||
|
||||
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 {
|
||||
@@ -197,6 +208,25 @@ extension PreReleaseOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func configPreReleaseStrategy() throws -> Configuration.PreReleaseStrategy? {
|
||||
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 {
|
||||
@@ -207,4 +237,13 @@ extension SemVarOptions {
|
||||
requireExistingSemVar: requireExistingSemvar
|
||||
)
|
||||
}
|
||||
|
||||
func configSemVarOptions() throws -> Configuration.SemVar {
|
||||
try .init(
|
||||
preRelease: preRelease.configPreReleaseStrategy(),
|
||||
requireExistingFile: requireExistingFile,
|
||||
requireExistingSemVar: requireExistingSemvar
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
48
Sources/cli-version/UtilsCommand.swift
Normal file
48
Sources/cli-version/UtilsCommand.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import ArgumentParser
|
||||
import ConfigurationClient
|
||||
import CustomDump
|
||||
import Dependencies
|
||||
import FileClient
|
||||
import Foundation
|
||||
|
||||
struct UtilsCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "utils",
|
||||
abstract: "Utility commands",
|
||||
subcommands: [
|
||||
DumpConfig.self
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
extension UtilsCommand {
|
||||
struct DumpConfig: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "dump-config",
|
||||
abstract: "Show the parsed configuration."
|
||||
)
|
||||
|
||||
@Argument(
|
||||
help: """
|
||||
Optional path to the configuration file, if not supplied will search the current directory
|
||||
""",
|
||||
completion: .file(extensions: ["toml", "json"])
|
||||
)
|
||||
var file: String?
|
||||
|
||||
func run() async throws {
|
||||
try await withDependencies {
|
||||
$0.fileClient = .liveValue
|
||||
$0.configurationClient = .liveValue
|
||||
} operation: {
|
||||
@Dependency(\.configurationClient) var configurationClient
|
||||
|
||||
let configuration = try await configurationClient.findAndLoad(
|
||||
file != nil ? URL(filePath: file!) : nil
|
||||
)
|
||||
|
||||
customDump(configuration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user