From 6662ce2ceee6c43f0eb5d21cb780cd7208633ea4 Mon Sep 17 00:00:00 2001 From: Jeffrey Macko Date: Sat, 14 Dec 2019 18:56:00 +0100 Subject: [PATCH] Update format --- .githooks/pre-commit | 2 +- .swift-format | 2 +- README.md | 21 +++++++++++++++++++ .../PlatformLookup/PlatformLookup+Error.swift | 16 ++++++++++++++ TODO.md | 2 ++ findDevicePlatform.swift | 18 ++++++++++++++++ 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 findDevicePlatform.swift diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 63d5b7c..69de706 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -16,7 +16,7 @@ elif ! [ -x "$(command -v swift-format)" ]; then ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/generate-pipeline /usr/local/bin/generate-pipeline else echo "Linting..." - git diff --diff-filter=d --cached --name-only | grep -E '\.(swift)$' | xargs -I{} swift-format -m lint --configuration .swift-format -i {} + git diff --diff-filter=d --cached --name-only | grep -E '\.(swift)$' | xargs -I{} swift-format -m lint --configuration .swift-format {} echo "Auto-Formatting..." git diff --diff-filter=d --cached --name-only | grep -E '\.(swift)$' | xargs -I{} swift-format -m format -r --configuration .swift-format -i {} fi diff --git a/.swift-format b/.swift-format index 5d4fb66..0abec54 100644 --- a/.swift-format +++ b/.swift-format @@ -16,7 +16,7 @@ "AlwaysUseLowerCamelCase" : true, "AmbiguousTrailingClosureOverload" : true, "BeginDocumentationCommentWithOneLineSummary" : true, - "BlankLineBetweenMembers" : true, + "BlankLineBetweenMembers" : false, "CaseIndentLevelEqualsSwitch" : true, "DoNotUseSemicolons" : true, "DontRepeatTypeInStaticProperties" : true, diff --git a/README.md b/README.md index a50f3f0..556f739 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,27 @@ This package help to find/filter/sort all devices and runtimes available in xcrun simctl. ```swift +#!/usr/bin/swift sh + +import Foundation +import PlatformLookup // @mackoj + +func findDevicePlatform(_ args: [String]) throws { + if let platform: String = try PlatformLookup.findADeviceForLastOSVersion() { + // Expecting: iOS Simulator,name=iPhone 11 Pro Max,OS=13.2 + print(platform) + } else { + print("👉 Failure 💩") + exit(EXIT_FAILURE) + } +} + +do { + try findDevicePlatform(CommandLine.arguments) +} catch { + print(error.localizedDescription) + exit(EXIT_FAILURE) +} ``` # SimulatorControl 📲 diff --git a/Sources/PlatformLookup/PlatformLookup+Error.swift b/Sources/PlatformLookup/PlatformLookup+Error.swift index 43ca461..214ef47 100644 --- a/Sources/PlatformLookup/PlatformLookup+Error.swift +++ b/Sources/PlatformLookup/PlatformLookup+Error.swift @@ -6,6 +6,7 @@ extension PlatformLookup { case failedToInitializeDataIsNotValid case unknowDeviceFamilly(String) case noRuntimeFound + /// A localized message describing what error occurred. public var errorDescription: String? { switch self { case .failedToInitializeDataIsNotValid: @@ -18,5 +19,20 @@ extension PlatformLookup { case .noRuntimeFound: return NSLocalizedString("Runtime unknown", comment: "Unknown Runtime") } } + /// A localized message describing the reason for the failure. + public var failureReason: String? { + return "failureReason" // switch self { + // case .failedToInitializeDataIsNotValid: + // <#code#> + // case .unknowDeviceFamilly(_): + // <#code#> + // case .noRuntimeFound: + // <#code#> + // } + } + /// A localized message describing how one might recover from the failure. + public var recoverySuggestion: String? { return "failureReason" } + /// A localized message providing "help" text if the user requests help. + public var helpAnchor: String? { return "failureReason" } } } diff --git a/TODO.md b/TODO.md index c2a7f12..c5f1938 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,7 @@ ## P0 - [ ] Add missing tests - [ ] Remove all the warnings +- [ ] Add simple script to call them ## P1 - [ ] Code Documentation @@ -14,3 +15,4 @@ - [ ] PR Boiler plate - [ ] Auto review - [ ] Dr String +- [ ] How to help translate error message diff --git a/findDevicePlatform.swift b/findDevicePlatform.swift new file mode 100755 index 0000000..076a8f5 --- /dev/null +++ b/findDevicePlatform.swift @@ -0,0 +1,18 @@ +import Foundation +// import PlatformLookup // mackoj/SimulatorControl ~> 0.8.0 +import PlatformLookup // https://github.com/mackoj/SimulatorControl == a037a15 + +func findDevicePlatform(_ args: [String]) throws { + if let platform:String = try PlatformLookup.findADeviceForLastOSVersion() { + // Expecting: iOS Simulator,name=iPhone 11 Pro Max,OS=13.2 + print(platform) + } else { + print("👉 Failure 💩") + exit(EXIT_FAILURE) + } +} + +do { try findDevicePlatform(CommandLine.arguments) } catch { + print(error.localizedDescription) + exit(EXIT_FAILURE) +}