aerospace fork
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import Commonimport Foundation
let configDotfileName = ".deewm.toml"func findCustomConfigUrl() -> ConfigFile { let xdgConfigHome = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"].map { URL(filePath: $0) } ?? FileManager.default.homeDirectoryForCurrentUser.appending(path: ".config/") let candidates: [URL] = switch serverArgs.configLocation { case let configLocation?: [URL(filePath: configLocation)] case nil: [ FileManager.default.homeDirectoryForCurrentUser.appending(path: configDotfileName), xdgConfigHome.appending(path: "deewm").appending(path: "deewm.toml"), ] } let existingCandidates: [URL] = candidates.filter { (candidate: URL) in FileManager.default.fileExists(atPath: candidate.path) } let count = existingCandidates.count return switch count { case 0: .noCustomConfigExists case 1: .file(existingCandidates.first.orDie()) default: .ambiguousConfigError(existingCandidates) }}
enum ConfigFile { case file(URL), ambiguousConfigError(_ candidates: [URL]), noCustomConfigExists
var urlOrNil: URL? { return switch self { case .file(let url): url case .ambiguousConfigError, .noCustomConfigExists: nil } }}