-
-
Notifications
You must be signed in to change notification settings - Fork 89
Introduce TOML configuration support and deprecate JSON config (#68) #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Guria
wants to merge
1
commit into
mikker:main
Choose a base branch
from
Guria:codex-toml-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
Leader Key.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import AppKit | ||
| import Foundation | ||
|
|
||
| /// Resolves application names to their full paths | ||
| /// Supports: | ||
| /// - Full paths: /Applications/Safari.app | ||
| /// - App names: "Safari", "Terminal", "Visual Studio Code" | ||
| /// - Partial matches: "Code" → "Visual Studio Code.app" | ||
| struct AppResolver { | ||
|
|
||
| /// Standard directories to search for applications | ||
| private static let searchPaths: [String] = [ | ||
| "/Applications", | ||
| "/System/Applications", | ||
| "/System/Applications/Utilities", | ||
| "~/Applications", | ||
| "/Applications/Utilities", | ||
| ] | ||
| private static let expandedSearchPaths: [String] = searchPaths.map { | ||
| ($0 as NSString).expandingTildeInPath | ||
| } | ||
|
|
||
| /// Resolve an app name or path to a full application path | ||
| /// - Parameter value: App name (e.g., "Terminal") or path (e.g., "/Applications/Safari.app") | ||
| /// - Returns: The resolved full path, or the original value if not resolvable | ||
| static func resolve(_ value: String) -> String { | ||
| // Already a full path | ||
| if value.hasPrefix("/") || value.hasPrefix("~") { | ||
| return (value as NSString).expandingTildeInPath | ||
| } | ||
|
|
||
| // If it ends with .app, search for it | ||
| if value.hasSuffix(".app") { | ||
| if let path = findApp(named: String(value.dropLast(4))) { | ||
| return path | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| // Try to find the app by name | ||
| if let path = findApp(named: value) { | ||
| return path | ||
| } | ||
|
|
||
| // Return original value (might be a command or URL) | ||
| return value | ||
| } | ||
|
|
||
| /// Find an application by name in standard locations | ||
| /// - Parameter name: The application name without .app extension | ||
| /// - Returns: Full path to the application, or nil if not found | ||
| static func findApp(named name: String) -> String? { | ||
| let appName = name.hasSuffix(".app") ? name : "\(name).app" | ||
|
|
||
| // First try exact match | ||
| for searchPath in expandedSearchPaths { | ||
| let fullPath = (searchPath as NSString).appendingPathComponent(appName) | ||
| if FileManager.default.fileExists(atPath: fullPath) { | ||
| return fullPath | ||
| } | ||
| } | ||
|
|
||
| // Try case-insensitive match | ||
| for searchPath in expandedSearchPaths { | ||
| if let match = findCaseInsensitive(name: name, in: searchPath) { | ||
| return match | ||
| } | ||
| } | ||
|
|
||
| // Try using Launch Services to find the app | ||
| if let bundleURL = NSWorkspace.shared.urlForApplication( | ||
| withBundleIdentifier: bundleIdentifierGuess(for: name)) | ||
| { | ||
| return bundleURL.path | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| /// Find app case-insensitively in a directory | ||
| private static func findCaseInsensitive(name: String, in directory: String) -> String? { | ||
| let lowercaseName = name.lowercased() | ||
|
|
||
| guard | ||
| let contents = try? FileManager.default.contentsOfDirectory( | ||
| atPath: directory) | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
| var prefixMatch: (name: String, path: String)? | ||
| var containsMatch: (name: String, path: String)? | ||
|
|
||
| func updateMatch( | ||
| _ match: inout (name: String, path: String)?, | ||
| candidateName: String, | ||
| candidatePath: String | ||
| ) { | ||
| if let current = match { | ||
| if candidateName.count < current.name.count { | ||
| match = (candidateName, candidatePath) | ||
| } | ||
| } else { | ||
| match = (candidateName, candidatePath) | ||
| } | ||
| } | ||
|
|
||
| for item in contents where item.hasSuffix(".app") { | ||
| let itemName = String(item.dropLast(4)) | ||
| let lowercasedItemName = itemName.lowercased() | ||
| if lowercasedItemName == lowercaseName { | ||
| return (directory as NSString).appendingPathComponent(item) | ||
| } | ||
|
|
||
| let itemPath = (directory as NSString).appendingPathComponent(item) | ||
|
|
||
| // Partial matching: exact (case-insensitive) is first, then prefix, then shortest contains. | ||
| if lowercasedItemName.hasPrefix(lowercaseName) { | ||
| updateMatch(&prefixMatch, candidateName: lowercasedItemName, candidatePath: itemPath) | ||
| } else if lowercasedItemName.contains(lowercaseName) { | ||
| updateMatch(&containsMatch, candidateName: lowercasedItemName, candidatePath: itemPath) | ||
| } | ||
| } | ||
|
|
||
| if let prefixMatch = prefixMatch { | ||
| return prefixMatch.path | ||
| } | ||
|
|
||
| if let containsMatch = containsMatch { | ||
| return containsMatch.path | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| /// Guess the bundle identifier for common apps | ||
| private static func bundleIdentifierGuess(for name: String) -> String { | ||
| // Try a generic pattern | ||
| return "com.apple.\(name.replacingOccurrences(of: " ", with: ""))" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description uses parentheses for 'JSON legacy' which could be clearer. Consider revising to 'Configuration management with TOML format (JSON deprecated) and validation' for better clarity.