CLI: add --version flag

This commit is contained in:
Peter Steinberger
2025-12-07 00:55:33 +00:00
parent 8b20e0166d
commit 0f71667625

View File

@@ -34,6 +34,9 @@ struct ClawdisCLI {
} catch CLIError.help { } catch CLIError.help {
printHelp() printHelp()
exit(0) exit(0)
} catch CLIError.version {
printVersion()
exit(0)
} catch { } catch {
fputs("clawdis-mac error: \(error)\n", stderr) fputs("clawdis-mac error: \(error)\n", stderr)
exit(2) exit(2)
@@ -49,6 +52,8 @@ struct ClawdisCLI {
switch command { switch command {
case "--help", "-h", "help": case "--help", "-h", "help":
throw CLIError.help throw CLIError.help
case "--version", "-V", "version":
throw CLIError.version
case "notify": case "notify":
var title: String? var title: String?
@@ -153,6 +158,14 @@ struct ClawdisCLI {
print(usage) print(usage)
} }
private static func printVersion() {
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "unknown"
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""
let git = Bundle.main.object(forInfoDictionaryKey: "ClawdisGitCommit") as? String ?? "unknown"
let ts = Bundle.main.object(forInfoDictionaryKey: "ClawdisBuildTimestamp") as? String ?? "unknown"
print("clawdis-mac \(version) (\(build)) git:\(git) built:\(ts)")
}
private static func send(request: Request) async throws -> Response { private static func send(request: Request) async throws -> Response {
let conn = NSXPCConnection(machServiceName: serviceName) let conn = NSXPCConnection(machServiceName: serviceName)
let interface = NSXPCInterface(with: ClawdisXPCProtocol.self) let interface = NSXPCInterface(with: ClawdisXPCProtocol.self)
@@ -172,7 +185,7 @@ struct ClawdisCLI {
} }
} }
enum CLIError: Error { case help } enum CLIError: Error { case help, version }
extension [String] { extension [String] {
mutating func popFirst() -> String? { mutating func popFirst() -> String? {