Renamed to cli version.
This commit is contained in:
46
Sources/cli-version/GenerateCommand.swift
Normal file
46
Sources/cli-version/GenerateCommand.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
import ArgumentParser
|
||||
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.",
|
||||
discussion: "This command can be interacted with directly, outside of the plugin usage context.",
|
||||
version: VERSION ?? "0.0.0"
|
||||
)
|
||||
|
||||
@OptionGroup var shared: SharedOptions
|
||||
|
||||
func run() throws {
|
||||
@Dependency(\.logger) var logger: Logger
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
|
||||
let targetUrl = parseTarget(shared.target)
|
||||
let fileUrl = targetUrl.appendingPathComponent(shared.fileName)
|
||||
|
||||
let fileString = fileUrl.fileString()
|
||||
|
||||
guard !FileManager.default.fileExists(atPath: fileUrl.absoluteString) else {
|
||||
logger.info("File already exists at path.")
|
||||
throw GenerationError.fileExists(path: fileString)
|
||||
}
|
||||
|
||||
if !shared.dryRun {
|
||||
try fileClient.write(string: optionalTemplate, to: fileUrl)
|
||||
logger.info("Generated file at: \(fileString)")
|
||||
} else {
|
||||
logger.info("Would generate file at: \(fileString)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate enum GenerationError: Error {
|
||||
case fileExists(path: String)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user