31 lines
999 B
Swift
31 lines
999 B
Swift
import Commander
|
|
import Foundation
|
|
import Swabble
|
|
|
|
@MainActor
|
|
struct TestHookCommand: ParsableCommand {
|
|
@Argument(help: "Text to send to hook") var text: String
|
|
@Option(name: .long("config"), help: "Path to config JSON") var configPath: String?
|
|
|
|
static var commandDescription: CommandDescription {
|
|
CommandDescription(commandName: "test-hook", abstract: "Invoke the configured hook with text")
|
|
}
|
|
|
|
init() {}
|
|
|
|
init(parsed: ParsedValues) {
|
|
self.init()
|
|
if let positional = parsed.positional.first { self.text = positional }
|
|
if let cfg = parsed.options["config"]?.last { self.configPath = cfg }
|
|
}
|
|
|
|
mutating func run() async throws {
|
|
let cfg = try ConfigLoader.load(at: self.configURL)
|
|
let runner = HookRunner(config: cfg)
|
|
try await runner.run(job: HookJob(text: self.text, timestamp: Date()))
|
|
print("hook invoked")
|
|
}
|
|
|
|
private var configURL: URL? { self.configPath.map { URL(fileURLWithPath: $0) } }
|
|
}
|