Skip to content

Commit f8cd19b

Browse files
p-linnaneclaude
andauthored
fix: resolve CLI version from app bundle when invoked via symlink (#305)
`Bundle.main` doesn't resolve to the `.app` bundle when the CLI is invoked through a symlink (e.g. Homebrew). Fall back to walking up from the resolved executable path to find the enclosing app bundle. Signed-off-by: Patrick Linnane <patrick@linnane.io> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a4dfb81 commit f8cd19b

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

macOSdbApp/Bootstrap/EntryPoint.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ struct MacOSdbCLI: AsyncParsableCommand {
2323
nonisolated static let configuration = CommandConfiguration(
2424
commandName: "macosdb",
2525
abstract: "Browse and compare open source components bundled in macOS releases.",
26-
version: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "dev",
26+
version: appVersion,
2727
subcommands: [ListCommand.self, ShowCommand.self, CompareCommand.self, ScanCommand.self]
2828
)
29+
30+
/// Falls back to the enclosing `.app` bundle when `Bundle.main` misses (e.g. symlink invocation).
31+
private static var appVersion: String {
32+
if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
33+
return version
34+
}
35+
var url = URL(fileURLWithPath: ProcessInfo.processInfo.arguments[0]).resolvingSymlinksInPath()
36+
while url.path != "/" {
37+
if url.pathExtension == "app", let bundle = Bundle(url: url),
38+
let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
39+
return version
40+
}
41+
url = url.deletingLastPathComponent()
42+
}
43+
return "dev"
44+
}
2945
}

0 commit comments

Comments
 (0)