Skip to content

Commit 7cde9ba

Browse files
authored
On avance vers la 1.0 (#6)
* Improve testing * Remove __Snapshots__ * Update Swift Format * Simplification de la configuration swift format * Fix formatage * Add cli interface * Sa avance peniblement * Fix * On avance sur le command parser * Improve tooling * Need to rework the errors * Improve formating * Fix bitrise lookup * bitrise * formmating
1 parent 7f95fac commit 7cde9ba

21 files changed

+647
-180
lines changed

.githooks/pre-commit

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ if ! [ -x "$(command -v swift)" ]; then
55
echo 'Error: swift is not installed.' >&2
66
echo 'You should install it before continuing' >&2
77
exit 1
8-
elif ! [ -x "$(command -v swift-format)" ]; then
8+
fi
9+
10+
if ! [ -x "$(command -v swift-format)" ]; then
911
echo 'Error: swift-format is not installed.' >&2
1012
git clone https://github.com/apple/swift-format.git /tmp/__hawkci__/swift-format
1113
cd /tmp/__hawkci__/swift-format
@@ -22,6 +24,13 @@ else
2224
echo "You might need to re-commit to commit the updated formmated code"
2325
fi
2426

27+
if ! [ -x "$(command -v generate-enum-properties)" ]; then
28+
echo "Installing swift-enum-properties"
29+
git clone https://github.com/pointfreeco/swift-enum-properties.git /tmp/__hawkci__/swift-enum-properties
30+
cd /tmp/__hawkci__/swift-enum-properties
31+
make install
32+
fi
33+
2534
#
2635
# An example hook script to verify what is about to be committed.
2736
# Called by "git commit" with no arguments. The hook should

.swift-format

+1-47
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,7 @@
11
{
2-
"blankLineBetweenMembers" : {
3-
"ignoreSingleLineProperties" : true
4-
},
5-
"indentation" : {
6-
"spaces" : 2
7-
},
8-
"indentConditionalCompilationBlocks" : true,
9-
"lineBreakBeforeControlFlowKeywords" : false,
2+
"lineLength" : 80,
103
"lineBreakBeforeEachArgument" : true,
11-
"lineLength" : 100,
12-
"maximumBlankLines" : 1,
134
"respectsExistingLineBreaks" : false,
14-
"rules" : {
15-
"AllPublicDeclarationsHaveDocumentation" : true,
16-
"AlwaysUseLowerCamelCase" : true,
17-
"AmbiguousTrailingClosureOverload" : true,
18-
"BeginDocumentationCommentWithOneLineSummary" : true,
19-
"BlankLineBetweenMembers" : false,
20-
"CaseIndentLevelEqualsSwitch" : true,
21-
"DoNotUseSemicolons" : true,
22-
"DontRepeatTypeInStaticProperties" : true,
23-
"FullyIndirectEnum" : true,
24-
"GroupNumericLiterals" : true,
25-
"IdentifiersMustBeASCII" : true,
26-
"MultiLineTrailingCommas" : true,
27-
"NeverForceUnwrap" : true,
28-
"NeverUseForceTry" : true,
29-
"NeverUseImplicitlyUnwrappedOptionals" : true,
30-
"NoAccessLevelOnExtensionDeclaration" : true,
31-
"NoBlockComments" : true,
32-
"NoCasesWithOnlyFallthrough" : true,
33-
"NoEmptyTrailingClosureParentheses" : true,
34-
"NoLabelsInCasePatterns" : true,
35-
"NoLeadingUnderscores" : true,
36-
"NoParensAroundConditions" : true,
37-
"NoVoidReturnOnFunctionSignature" : true,
38-
"OneCasePerLine" : true,
39-
"OneVariableDeclarationPerLine" : true,
40-
"OnlyOneTrailingClosureArgument" : true,
41-
"OrderedImports" : true,
42-
"ReturnVoidInsteadOfEmptyTuple" : true,
43-
"UseEnumForNamespacing" : true,
44-
"UseLetInEveryBoundCaseVariable" : true,
45-
"UseShorthandTypeNames" : true,
46-
"UseSingleLinePropertyGetter" : true,
47-
"UseSynthesizedInitializer" : true,
48-
"UseTripleSlashForDocumentationComments" : true,
49-
"ValidateDocumentationComments" : true
50-
},
515
"tabWidth" : 4,
526
"version" : 1
537
}

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ build:
55
swift build
66

77
format:
8-
swift-format -m format --configuration .swift-format -r -i Sources
8+
swift-format -m format --configuration .swift-format -r -i Sources/**/*.swift
99

1010
lint:
11-
swift-format -m lint --configuration .swift-format -r -i Sources
11+
swift-format -m lint --configuration .swift-format -r -i Sources/**/*.swift
12+
13+
generate-enum-properties:
14+
generate-enum-properties Sources/**/*.swift
1215

1316
gitignore-flush:
1417
git rm -r --cached .

Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
"version": "1.7.0"
1111
}
1212
},
13+
{
14+
"package": "swift-tools-support-core",
15+
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
16+
"state": {
17+
"branch": "master",
18+
"revision": "edc19d30a674cb9f3311b77ffb406dc7c5d2f540",
19+
"version": null
20+
}
21+
},
1322
{
1423
"package": "Version",
1524
"repositoryURL": "https://github.com/mrackwitz/Version.git",

Package.swift

+19-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,33 @@ let package = Package(
77
name: "PlatformLookup",
88
platforms: [.macOS(.v10_14)],
99
products: [
10+
.executable(name: "cli", targets: ["cli"]),
1011
.library(name: "SimulatorControl", targets: ["SimulatorControl"]),
1112
.library(name: "Shell", targets: ["Shell"]),
1213
.library(name: "PlatformLookup", targets: ["PlatformLookup"]),
1314
],
1415
dependencies: [
16+
.package(
17+
url: "https://github.com/apple/swift-tools-support-core.git",
18+
.branch("master")
19+
), // en attendant une release stable
1520
.package(url: "https://github.com/mrackwitz/Version.git", from: "0.7.2"),
16-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.7.0"),
21+
.package(
22+
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
23+
from: "1.7.0"
24+
),
1725
],
1826
targets: [
19-
.target(name: "PlatformLookup", dependencies: ["SimulatorControl", "Shell"]),
20-
.target(name: "Shell"), .target(name: "SimulatorControl", dependencies: ["Version"]),
21-
.testTarget(name: "PlatformLookupTests", dependencies: ["PlatformLookup", "SnapshotTesting"]),
22-
.testTarget(name: "ShellTests", dependencies: ["Shell", "SnapshotTesting"]),
27+
.target(name: "cli", dependencies: ["PlatformLookup", "SwiftToolsSupport"]),
28+
.target(
29+
name: "PlatformLookup",
30+
dependencies: ["SimulatorControl", "Shell"]
31+
), .target(name: "Shell"),
32+
.target(name: "SimulatorControl", dependencies: ["Version"]),
33+
.testTarget(
34+
name: "PlatformLookupTests",
35+
dependencies: ["PlatformLookup", "SnapshotTesting"]
36+
), .testTarget(name: "ShellTests", dependencies: ["Shell"]),
2337
],
2438
swiftLanguageVersions: [.v5]
2539
)

Sources/PlatformLookup/Platform.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import SimulatorControl
33

44
/// <#Description#>
55
public struct Platform: Equatable, Codable {
6-
let devices: [Device]
7-
let runtime: Runtime
6+
public let devices: [Device]
7+
public let runtime: Runtime
88

99
/// <#Description#>
1010
/// - Parameters:

Sources/PlatformLookup/PlatformLookup+DeviceFamily.swift

+7
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ extension PlatformLookup {
1515
case .appleWatch: return "watchOS"
1616
}
1717
}
18+
var simulatorName: String {
19+
switch self {
20+
case .iPhone, .iPad: return "iOS Simulator"
21+
case .appleTV: return "tvOS Simulator"
22+
case .appleWatch: return "watchOS Simulator"
23+
}
24+
}
1825
}
1926
}

Sources/PlatformLookup/PlatformLookup+Error.swift

+111-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ extension PlatformLookup {
44
/// <#Description#>
55
public enum PlatformLookupError: Error, LocalizedError {
66
case failedToInitializeDataIsNotValid
7-
case unknowDeviceFamilly(String)
7+
case invalidIndex(file: String, function: String, line: Int)
8+
case noResultForThisCombinaison(device: String, runtime: String)
89
case noRuntimeFound
10+
case thisShouldNeverAppen(file: String, function: String, line: Int)
11+
case unknowDevice(String)
12+
case unknowRuntime(String)
913
/// A localized message describing what error occurred.
1014
public var errorDescription: String? {
1115
switch self {
@@ -14,25 +18,118 @@ extension PlatformLookup {
1418
"Invalid data at initilisation of `PlatformLookup`",
1519
comment: "Invalid Data"
1620
)
17-
case .unknowDeviceFamilly(let input):
18-
return NSLocalizedString("Device familly \(input) unknown", comment: "Unknown Device")
19-
case .noRuntimeFound: return NSLocalizedString("Runtime unknown", comment: "Unknown Runtime")
21+
case .invalidIndex(let file, let function, let line):
22+
return NSLocalizedString(
23+
"Invalid Index at \(function) in \(file):\(line)",
24+
comment: "Invalid Index"
25+
)
26+
case .noResultForThisCombinaison(let device, let runtime):
27+
return NSLocalizedString(
28+
"No result found for device: \(device), runtime: \(runtime)",
29+
comment: "Invalid device/runtime combinaison"
30+
)
31+
case .noRuntimeFound:
32+
return NSLocalizedString(
33+
"No runtime found",
34+
comment: "No runtime found"
35+
)
36+
case .thisShouldNeverAppen(let file, let function, let line):
37+
let message =
38+
"This should really never happen please look at \(function) in \(file):\(line)"
39+
#if DEBUG
40+
assertionFailure(message)
41+
#endif
42+
return NSLocalizedString(message, comment: "Unknown Runtime")
43+
case .unknowDevice(let device):
44+
return NSLocalizedString("Unknown \(device)", comment: "unknown device")
45+
case .unknowRuntime(let runtime):
46+
return NSLocalizedString(
47+
"Unknown \(runtime)",
48+
comment: "Unknown runtime"
49+
)
2050
}
2151
}
2252
/// A localized message describing the reason for the failure.
2353
public var failureReason: String? {
24-
return "failureReason" // switch self {
25-
// case .failedToInitializeDataIsNotValid:
26-
// <#code#>
27-
// case .unknowDeviceFamilly(_):
28-
// <#code#>
29-
// case .noRuntimeFound:
30-
// <#code#>
31-
// }
54+
return "failureReason - need to be implemented"
3255
}
3356
/// A localized message describing how one might recover from the failure.
34-
public var recoverySuggestion: String? { return "failureReason" }
57+
public var recoverySuggestion: String? {
58+
return "recoverySuggestion - need to be implemented"
59+
}
3560
/// A localized message providing "help" text if the user requests help.
36-
public var helpAnchor: String? { return "failureReason" }
61+
public var helpAnchor: String? {
62+
return "helpAnchor - need to be implemented"
63+
}
64+
public var invalidIndex: (file: String, function: String, line: Int)? {
65+
get {
66+
guard case let .invalidIndex(value) = self else { return nil }
67+
return value
68+
}
69+
set {
70+
guard case .invalidIndex = self, let newValue = newValue else { return }
71+
self = .invalidIndex(
72+
file: newValue.0,
73+
function: newValue.1,
74+
line: newValue.2
75+
)
76+
}
77+
}
78+
public var noResultForThisCombinaison: (device: String, runtime: String)? {
79+
get {
80+
guard case let .noResultForThisCombinaison(value) = self else {
81+
return nil
82+
}
83+
return value
84+
}
85+
set {
86+
guard case .noResultForThisCombinaison = self, let newValue = newValue
87+
else { return }
88+
self = .noResultForThisCombinaison(
89+
device: newValue.0,
90+
runtime: newValue.1
91+
)
92+
}
93+
}
94+
public var thisShouldNeverAppen:
95+
(file: String, function: String, line: Int)?
96+
{
97+
get {
98+
guard case let .thisShouldNeverAppen(value) = self else { return nil }
99+
return value
100+
}
101+
set {
102+
guard case .thisShouldNeverAppen = self, let newValue = newValue else {
103+
return
104+
}
105+
self = .thisShouldNeverAppen(
106+
file: newValue.0,
107+
function: newValue.1,
108+
line: newValue.2
109+
)
110+
}
111+
}
112+
public var unknowDevice: String? {
113+
get {
114+
guard case let .unknowDevice(value) = self else { return nil }
115+
return value
116+
}
117+
set {
118+
guard case .unknowDevice = self, let newValue = newValue else { return }
119+
self = .unknowDevice(newValue)
120+
}
121+
}
122+
public var unknowRuntime: String? {
123+
get {
124+
guard case let .unknowRuntime(value) = self else { return nil }
125+
return value
126+
}
127+
set {
128+
guard case .unknowRuntime = self, let newValue = newValue else {
129+
return
130+
}
131+
self = .unknowRuntime(newValue)
132+
}
133+
}
37134
}
38135
}

Sources/PlatformLookup/PlatformLookup+Filters.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ extension PlatformLookup {
88
/// - Parameters:
99
/// - name: <#name description#>
1010
/// - version: <#version description#>
11-
static public func filterRuntime(_ name: String, version: String? = nil) -> ((Runtime) -> Bool) {
11+
static public func filterRuntime(_ name: String, version: String? = nil) -> (
12+
(Runtime) -> Bool
13+
) {
1214
return { runtime in let f1 = runtime.name.contains(name)
1315
guard let version = version else { return f1 }
1416
return f1 && runtime.version.contains(version)
@@ -18,17 +20,19 @@ extension PlatformLookup {
1820
// MARK: - Device Filter
1921
/// <#Description#>
2022
/// - Parameter deviceName: <#deviceName description#>
21-
static public func filterDeviceName(_ deviceName: String) -> ((Device) -> Bool) {
22-
return { $0.name.contains(deviceName) }
23-
}
23+
static public func filterDeviceName(_ deviceName: String) -> (
24+
(Device) -> Bool
25+
) { return { $0.name.contains(deviceName) } }
2426
/// <#Description#>
2527
/// - Parameters:
2628
/// - deviceFamily: <#deviceFamily description#>
2729
/// - isAvailable: <#isAvailable description#>
28-
static public func filterDeviceFamily(_ deviceFamily: DeviceFamily, isAvailable: Bool? = nil) -> (
29-
(Device) -> Bool
30-
) {
31-
return { device in let containExpectedDevice = device.name.contains(deviceFamily.rawValue)
30+
static public func filterDeviceFamily(
31+
_ deviceFamily: DeviceFamily,
32+
isAvailable: Bool? = nil
33+
) -> ((Device) -> Bool) {
34+
return { device in
35+
let containExpectedDevice = device.name.contains(deviceFamily.rawValue)
3236
guard let isAvailable = isAvailable else { return containExpectedDevice }
3337
return (containExpectedDevice && isAvailable)
3438
}

0 commit comments

Comments
 (0)