Skip to content

Commit

Permalink
Merge pull request Carthage#69 from norio-nomura/nn-swift-3
Browse files Browse the repository at this point in the history
Support Swift 3.0
  • Loading branch information
mdiep committed Sep 20, 2016
2 parents cd9a165 + c414184 commit 6b5b451
Show file tree
Hide file tree
Showing 26 changed files with 305 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-03-24-a
3.0
14 changes: 3 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@ matrix:
exclude:
- script: placeholder # workaround for https://github.com/travis-ci/travis-ci/issues/4681
include:
- script: set -o pipefail && xcodebuild -workspace "$TRAVIS_XCODE_WORKSPACE" -scheme "$TRAVIS_XCODE_SCHEME" test | xcpretty
xcode_scheme: Commandant
os: osx
osx_image: xcode7.3
language: objective-c
env: JOB=Xcode7.3
- script: set -o pipefail && xcodebuild -workspace "$TRAVIS_XCODE_WORKSPACE" -scheme "$TRAVIS_XCODE_SCHEME" test | xcpretty
xcode_scheme: Commandant
os: osx
osx_image: xcode8
language: objective-c
env: JOB=Xcode8
- script: swift build
- script: SWIFT_GIT=`xcrun --find git` swift build
os: osx
osx_image: xcode7.3
osx_image: xcode8
language: objective-c
env: JOB=SPM
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/02090c7ede5a637b76e6df1710e83cd0bbe7dcdf/swiftenv-install.sh)"
- script: swift build
- script: swift build && swift test
env: JOB=Linux
sudo: required
dist: trusty
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" ~> 2.1.3
github "antitypical/Result" ~> 3.0
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "jspahrsummers/xcconfigs" ~> 0.9
github "Quick/Quick" ~> 0.9.3
github "Quick/Nimble" "188caeb"
github "Quick/Quick" "swift-3.0"
github "Quick/Nimble" "master"
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "Quick/Nimble" "188caeb094bc342614d8a5c706cd8bb9a6c355eb"
github "Quick/Quick" "v0.9.3"
github "antitypical/Result" "2.1.3"
github "Quick/Nimble" "fcc28b23f57b30382e5f182c238674694d7174cb"
github "Quick/Quick" "8f2bc636ecfa2cc20696f62548b38d4ab943e299"
github "antitypical/Result" "3.0.0"
github "jspahrsummers/xcconfigs" "0.9"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Nimble
Submodule Nimble updated 128 files
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Quick
Submodule Quick updated 117 files
37 changes: 20 additions & 17 deletions Commandant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
6C29EE8B1CA6241B0005DA40 /* Swift3to22.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C29EE8A1CA6241B0005DA40 /* Swift3to22.swift */; };
6C29EE8B1CA6241B0005DA40 /* LinuxSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C29EE8A1CA6241B0005DA40 /* LinuxSupport.swift */; };
CD2ED3411C1E6C5D0076092B /* Argument.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2ED3401C1E6C5D0076092B /* Argument.swift */; };
CD2ED3431C1E6D540076092B /* ArgumentType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2ED3421C1E6D540076092B /* ArgumentType.swift */; };
CD2ED3431C1E6D540076092B /* ArgumentProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2ED3421C1E6D540076092B /* ArgumentProtocol.swift */; };
CDFC88361C3C0612003AC8F8 /* CommandSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDFC88351C3C0612003AC8F8 /* CommandSpec.swift */; };
D00CCDDF1A20717400109F8C /* Commandant.h in Headers */ = {isa = PBXBuildFile; fileRef = D00CCDDE1A20717400109F8C /* Commandant.h */; settings = {ATTRIBUTES = (Public, ); }; };
D00CCDE51A20717400109F8C /* Commandant.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D00CCDD91A20717400109F8C /* Commandant.framework */; };
Expand All @@ -36,9 +36,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
6C29EE8A1CA6241B0005DA40 /* Swift3to22.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Swift3to22.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
6C29EE8A1CA6241B0005DA40 /* LinuxSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LinuxSupport.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
6CAD549C1D371A4E00A2D031 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LinuxMain.swift; path = Tests/LinuxMain.swift; sourceTree = SOURCE_ROOT; };
CD2ED3401C1E6C5D0076092B /* Argument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Argument.swift; sourceTree = "<group>"; };
CD2ED3421C1E6D540076092B /* ArgumentType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArgumentType.swift; sourceTree = "<group>"; };
CD2ED3421C1E6D540076092B /* ArgumentProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArgumentProtocol.swift; sourceTree = "<group>"; };
CDFC88351C3C0612003AC8F8 /* CommandSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandSpec.swift; sourceTree = "<group>"; };
D00CCDD91A20717400109F8C /* Commandant.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Commandant.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D00CCDDD1A20717400109F8C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -144,8 +145,10 @@
CDFC88351C3C0612003AC8F8 /* CommandSpec.swift */,
D00CCE281A20741C00109F8C /* OptionSpec.swift */,
D00CCDE91A20717400109F8C /* Supporting Files */,
6CAD549C1D371A4E00A2D031 /* LinuxMain.swift */,
);
path = Tests;
name = Tests;
path = Tests/CommandantTests;
sourceTree = "<group>";
};
D00CCDE91A20717400109F8C /* Supporting Files */ = {
Expand Down Expand Up @@ -229,11 +232,11 @@
children = (
CD2ED3401C1E6C5D0076092B /* Argument.swift */,
D00CCE2C1A2075ED00109F8C /* ArgumentParser.swift */,
CD2ED3421C1E6D540076092B /* ArgumentType.swift */,
CD2ED3421C1E6D540076092B /* ArgumentProtocol.swift */,
D00CCE261A20741300109F8C /* Command.swift */,
D00CCE2A1A20748500109F8C /* Errors.swift */,
D00CCE2E1A2075F700109F8C /* Option.swift */,
6C29EE8A1CA6241B0005DA40 /* Swift3to22.swift */,
6C29EE8A1CA6241B0005DA40 /* LinuxSupport.swift */,
D8169D861ACB942D00923FB0 /* Switch.swift */,
);
name = Core;
Expand Down Expand Up @@ -360,8 +363,8 @@
files = (
CD2ED3411C1E6C5D0076092B /* Argument.swift in Sources */,
D0BF14FB1A4C8957003147BC /* HelpCommand.swift in Sources */,
6C29EE8B1CA6241B0005DA40 /* Swift3to22.swift in Sources */,
CD2ED3431C1E6D540076092B /* ArgumentType.swift in Sources */,
6C29EE8B1CA6241B0005DA40 /* LinuxSupport.swift in Sources */,
CD2ED3431C1E6D540076092B /* ArgumentProtocol.swift in Sources */,
D00CCE2F1A2075F700109F8C /* Option.swift in Sources */,
D00CCE2B1A20748500109F8C /* Errors.swift in Sources */,
D8169D871ACB942D00923FB0 /* Switch.swift in Sources */,
Expand Down Expand Up @@ -398,7 +401,7 @@
ENABLE_TESTABILITY = YES;
MACOSX_DEPLOYMENT_TARGET = 10.9;
ONLY_ACTIVE_ARCH = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -410,7 +413,7 @@
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -457,7 +460,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
INFOPLIST_FILE = Tests/CommandantTests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -471,7 +474,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
INFOPLIST_FILE = Tests/CommandantTests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -483,7 +486,7 @@
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -513,7 +516,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
INFOPLIST_FILE = Tests/CommandantTests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -525,7 +528,7 @@
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -556,7 +559,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
INFOPLIST_FILE = Tests/CommandantTests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand Down
18 changes: 14 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import PackageDescription

let package = Package(
name: "Commandant",
dependencies: [
.Package(url: "https://github.com/antitypical/Result.git", "2.0.0")
]
name: "Commandant",
dependencies: {
#if os(macOS)
return [
.Package(url: "https://github.com/antitypical/Result.git", majorVersion: 3, minor: 0),
]
#else
return [
.Package(url: "https://github.com/antitypical/Result.git", majorVersion: 3, minor: 0),
.Package(url: "https://github.com/ikesyo/Nimble", "5.0.0-alpha.30"),
.Package(url: "https://github.com/norio-nomura/Quick", "0.10.0-alpha.30.gm.candidate"),
]
#endif
}()
)
44 changes: 22 additions & 22 deletions Sources/Commandant/Argument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,72 +25,72 @@ public struct Argument<T> {
self.usage = usage
}

private func invalidUsageError<ClientError>(value: String) -> CommandantError<ClientError> {
fileprivate func invalidUsageError<ClientError>(_ value: String) -> CommandantError<ClientError> {
let description = "Invalid value for '\(self)': \(value)"
return .UsageError(description: description)
return .usageError(description: description)
}
}

/// Evaluates the given argument in the given mode.
///
/// If parsing command line arguments, and no value was specified on the command
/// line, the argument's `defaultValue` is used.
public func <| <T: ArgumentType, ClientError>(mode: CommandMode, argument: Argument<T>) -> Result<T, CommandantError<ClientError>> {
public func <| <T: ArgumentProtocol, ClientError>(mode: CommandMode, argument: Argument<T>) -> Result<T, CommandantError<ClientError>> {
switch mode {
case let .Arguments(arguments):
case let .arguments(arguments):
guard let stringValue = arguments.consumePositionalArgument() else {
if let defaultValue = argument.defaultValue {
return .Success(defaultValue)
return .success(defaultValue)
} else {
return .Failure(missingArgumentError(argument.usage))
return .failure(missingArgumentError(argument.usage))
}
}

if let value = T.fromString(stringValue) {
return .Success(value)
if let value = T.from(string: stringValue) {
return .success(value)
} else {
return .Failure(argument.invalidUsageError(stringValue))
return .failure(argument.invalidUsageError(stringValue))
}

case .Usage:
return .Failure(informativeUsageError(argument))
case .usage:
return .failure(informativeUsageError(argument))
}
}

/// Evaluates the given argument list in the given mode.
///
/// If parsing command line arguments, and no value was specified on the command
/// line, the argument's `defaultValue` is used.
public func <| <T: ArgumentType, ClientError>(mode: CommandMode, argument: Argument<[T]>) -> Result<[T], CommandantError<ClientError>> {
public func <| <T: ArgumentProtocol, ClientError>(mode: CommandMode, argument: Argument<[T]>) -> Result<[T], CommandantError<ClientError>> {
switch mode {
case let .Arguments(arguments):
case let .arguments(arguments):
guard let firstValue = arguments.consumePositionalArgument() else {
if let defaultValue = argument.defaultValue {
return .Success(defaultValue)
return .success(defaultValue)
} else {
return .Failure(missingArgumentError(argument.usage))
return .failure(missingArgumentError(argument.usage))
}
}

var values = [T]()

guard let value = T.fromString(firstValue) else {
return .Failure(argument.invalidUsageError(firstValue))
guard let value = T.from(string: firstValue) else {
return .failure(argument.invalidUsageError(firstValue))
}

values.append(value)

while let nextValue = arguments.consumePositionalArgument() {
guard let value = T.fromString(nextValue) else {
return .Failure(argument.invalidUsageError(nextValue))
guard let value = T.from(string: nextValue) else {
return .failure(argument.invalidUsageError(nextValue))
}

values.append(value)
}

return .Success(values)
return .success(values)

case .Usage:
return .Failure(informativeUsageError(argument))
case .usage:
return .failure(informativeUsageError(argument))
}
}
Loading

0 comments on commit 6b5b451

Please sign in to comment.