Skip to content

Commit

Permalink
On avance vers la 1.0 (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mackoj authored Dec 17, 2019
1 parent 7f95fac commit 7cde9ba
Show file tree
Hide file tree
Showing 21 changed files with 647 additions and 180 deletions.
11 changes: 10 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ if ! [ -x "$(command -v swift)" ]; then
echo 'Error: swift is not installed.' >&2
echo 'You should install it before continuing' >&2
exit 1
elif ! [ -x "$(command -v swift-format)" ]; then
fi

if ! [ -x "$(command -v swift-format)" ]; then
echo 'Error: swift-format is not installed.' >&2
git clone https://github.com/apple/swift-format.git /tmp/__hawkci__/swift-format
cd /tmp/__hawkci__/swift-format
Expand All @@ -22,6 +24,13 @@ else
echo "You might need to re-commit to commit the updated formmated code"
fi

if ! [ -x "$(command -v generate-enum-properties)" ]; then
echo "Installing swift-enum-properties"
git clone https://github.com/pointfreeco/swift-enum-properties.git /tmp/__hawkci__/swift-enum-properties
cd /tmp/__hawkci__/swift-enum-properties
make install
fi

#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
Expand Down
48 changes: 1 addition & 47 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -1,53 +1,7 @@
{
"blankLineBetweenMembers" : {
"ignoreSingleLineProperties" : true
},
"indentation" : {
"spaces" : 2
},
"indentConditionalCompilationBlocks" : true,
"lineBreakBeforeControlFlowKeywords" : false,
"lineLength" : 80,
"lineBreakBeforeEachArgument" : true,
"lineLength" : 100,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : false,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : true,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : true,
"BlankLineBetweenMembers" : false,
"CaseIndentLevelEqualsSwitch" : true,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"MultiLineTrailingCommas" : true,
"NeverForceUnwrap" : true,
"NeverUseForceTry" : true,
"NeverUseImplicitlyUnwrappedOptionals" : true,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : true,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEnumForNamespacing" : true,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"ValidateDocumentationComments" : true
},
"tabWidth" : 4,
"version" : 1
}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ build:
swift build

format:
swift-format -m format --configuration .swift-format -r -i Sources
swift-format -m format --configuration .swift-format -r -i Sources/**/*.swift

lint:
swift-format -m lint --configuration .swift-format -r -i Sources
swift-format -m lint --configuration .swift-format -r -i Sources/**/*.swift

generate-enum-properties:
generate-enum-properties Sources/**/*.swift

gitignore-flush:
git rm -r --cached .
Expand Down
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
"version": "1.7.0"
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "master",
"revision": "edc19d30a674cb9f3311b77ffb406dc7c5d2f540",
"version": null
}
},
{
"package": "Version",
"repositoryURL": "https://github.com/mrackwitz/Version.git",
Expand Down
24 changes: 19 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ let package = Package(
name: "PlatformLookup",
platforms: [.macOS(.v10_14)],
products: [
.executable(name: "cli", targets: ["cli"]),
.library(name: "SimulatorControl", targets: ["SimulatorControl"]),
.library(name: "Shell", targets: ["Shell"]),
.library(name: "PlatformLookup", targets: ["PlatformLookup"]),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.branch("master")
), // en attendant une release stable
.package(url: "https://github.com/mrackwitz/Version.git", from: "0.7.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.7.0"),
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
from: "1.7.0"
),
],
targets: [
.target(name: "PlatformLookup", dependencies: ["SimulatorControl", "Shell"]),
.target(name: "Shell"), .target(name: "SimulatorControl", dependencies: ["Version"]),
.testTarget(name: "PlatformLookupTests", dependencies: ["PlatformLookup", "SnapshotTesting"]),
.testTarget(name: "ShellTests", dependencies: ["Shell", "SnapshotTesting"]),
.target(name: "cli", dependencies: ["PlatformLookup", "SwiftToolsSupport"]),
.target(
name: "PlatformLookup",
dependencies: ["SimulatorControl", "Shell"]
), .target(name: "Shell"),
.target(name: "SimulatorControl", dependencies: ["Version"]),
.testTarget(
name: "PlatformLookupTests",
dependencies: ["PlatformLookup", "SnapshotTesting"]
), .testTarget(name: "ShellTests", dependencies: ["Shell"]),
],
swiftLanguageVersions: [.v5]
)
4 changes: 2 additions & 2 deletions Sources/PlatformLookup/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import SimulatorControl

/// <#Description#>
public struct Platform: Equatable, Codable {
let devices: [Device]
let runtime: Runtime
public let devices: [Device]
public let runtime: Runtime

/// <#Description#>
/// - Parameters:
Expand Down
7 changes: 7 additions & 0 deletions Sources/PlatformLookup/PlatformLookup+DeviceFamily.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ extension PlatformLookup {
case .appleWatch: return "watchOS"
}
}
var simulatorName: String {
switch self {
case .iPhone, .iPad: return "iOS Simulator"
case .appleTV: return "tvOS Simulator"
case .appleWatch: return "watchOS Simulator"
}
}
}
}
125 changes: 111 additions & 14 deletions Sources/PlatformLookup/PlatformLookup+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ extension PlatformLookup {
/// <#Description#>
public enum PlatformLookupError: Error, LocalizedError {
case failedToInitializeDataIsNotValid
case unknowDeviceFamilly(String)
case invalidIndex(file: String, function: String, line: Int)
case noResultForThisCombinaison(device: String, runtime: String)
case noRuntimeFound
case thisShouldNeverAppen(file: String, function: String, line: Int)
case unknowDevice(String)
case unknowRuntime(String)
/// A localized message describing what error occurred.
public var errorDescription: String? {
switch self {
Expand All @@ -14,25 +18,118 @@ extension PlatformLookup {
"Invalid data at initilisation of `PlatformLookup`",
comment: "Invalid Data"
)
case .unknowDeviceFamilly(let input):
return NSLocalizedString("Device familly \(input) unknown", comment: "Unknown Device")
case .noRuntimeFound: return NSLocalizedString("Runtime unknown", comment: "Unknown Runtime")
case .invalidIndex(let file, let function, let line):
return NSLocalizedString(
"Invalid Index at \(function) in \(file):\(line)",
comment: "Invalid Index"
)
case .noResultForThisCombinaison(let device, let runtime):
return NSLocalizedString(
"No result found for device: \(device), runtime: \(runtime)",
comment: "Invalid device/runtime combinaison"
)
case .noRuntimeFound:
return NSLocalizedString(
"No runtime found",
comment: "No runtime found"
)
case .thisShouldNeverAppen(let file, let function, let line):
let message =
"This should really never happen please look at \(function) in \(file):\(line)"
#if DEBUG
assertionFailure(message)
#endif
return NSLocalizedString(message, comment: "Unknown Runtime")
case .unknowDevice(let device):
return NSLocalizedString("Unknown \(device)", comment: "unknown device")
case .unknowRuntime(let runtime):
return NSLocalizedString(
"Unknown \(runtime)",
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#>
// }
return "failureReason - need to be implemented"
}
/// A localized message describing how one might recover from the failure.
public var recoverySuggestion: String? { return "failureReason" }
public var recoverySuggestion: String? {
return "recoverySuggestion - need to be implemented"
}
/// A localized message providing "help" text if the user requests help.
public var helpAnchor: String? { return "failureReason" }
public var helpAnchor: String? {
return "helpAnchor - need to be implemented"
}
public var invalidIndex: (file: String, function: String, line: Int)? {
get {
guard case let .invalidIndex(value) = self else { return nil }
return value
}
set {
guard case .invalidIndex = self, let newValue = newValue else { return }
self = .invalidIndex(
file: newValue.0,
function: newValue.1,
line: newValue.2
)
}
}
public var noResultForThisCombinaison: (device: String, runtime: String)? {
get {
guard case let .noResultForThisCombinaison(value) = self else {
return nil
}
return value
}
set {
guard case .noResultForThisCombinaison = self, let newValue = newValue
else { return }
self = .noResultForThisCombinaison(
device: newValue.0,
runtime: newValue.1
)
}
}
public var thisShouldNeverAppen:
(file: String, function: String, line: Int)?
{
get {
guard case let .thisShouldNeverAppen(value) = self else { return nil }
return value
}
set {
guard case .thisShouldNeverAppen = self, let newValue = newValue else {
return
}
self = .thisShouldNeverAppen(
file: newValue.0,
function: newValue.1,
line: newValue.2
)
}
}
public var unknowDevice: String? {
get {
guard case let .unknowDevice(value) = self else { return nil }
return value
}
set {
guard case .unknowDevice = self, let newValue = newValue else { return }
self = .unknowDevice(newValue)
}
}
public var unknowRuntime: String? {
get {
guard case let .unknowRuntime(value) = self else { return nil }
return value
}
set {
guard case .unknowRuntime = self, let newValue = newValue else {
return
}
self = .unknowRuntime(newValue)
}
}
}
}
20 changes: 12 additions & 8 deletions Sources/PlatformLookup/PlatformLookup+Filters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ extension PlatformLookup {
/// - Parameters:
/// - name: <#name description#>
/// - version: <#version description#>
static public func filterRuntime(_ name: String, version: String? = nil) -> ((Runtime) -> Bool) {
static public func filterRuntime(_ name: String, version: String? = nil) -> (
(Runtime) -> Bool
) {
return { runtime in let f1 = runtime.name.contains(name)
guard let version = version else { return f1 }
return f1 && runtime.version.contains(version)
Expand All @@ -18,17 +20,19 @@ extension PlatformLookup {
// MARK: - Device Filter
/// <#Description#>
/// - Parameter deviceName: <#deviceName description#>
static public func filterDeviceName(_ deviceName: String) -> ((Device) -> Bool) {
return { $0.name.contains(deviceName) }
}
static public func filterDeviceName(_ deviceName: String) -> (
(Device) -> Bool
) { return { $0.name.contains(deviceName) } }
/// <#Description#>
/// - Parameters:
/// - deviceFamily: <#deviceFamily description#>
/// - isAvailable: <#isAvailable description#>
static public func filterDeviceFamily(_ deviceFamily: DeviceFamily, isAvailable: Bool? = nil) -> (
(Device) -> Bool
) {
return { device in let containExpectedDevice = device.name.contains(deviceFamily.rawValue)
static public func filterDeviceFamily(
_ deviceFamily: DeviceFamily,
isAvailable: Bool? = nil
) -> ((Device) -> Bool) {
return { device in
let containExpectedDevice = device.name.contains(deviceFamily.rawValue)
guard let isAvailable = isAvailable else { return containExpectedDevice }
return (containExpectedDevice && isAvailable)
}
Expand Down
Loading

0 comments on commit 7cde9ba

Please sign in to comment.