Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4 #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0
2 changes: 1 addition & 1 deletion Source/Argument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ extension String {

let actualRange = (characters.index(startIndex, offsetBy: range.lowerBound) ..< characters.index(endIndex, offsetBy: -distanceFromEndIndex))

return self[actualRange]
return String(self[actualRange])
}
}
2 changes: 1 addition & 1 deletion Source/Ask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public func ask(_ prompt: String, customizationBlock: ((AskSettings<String>) ->
- returns: The string casted to the type requested
- discussion: If the user enters a wrong type, ask will keep prompting until a correct value has been entered
*/
public func ask<T: ArgConvertibleType>(_ prompt: String, type: T.Type, customizationBlock: ((AskSettings<T>) -> Void)? = nil) -> T {
public func ask<T>(_ prompt: String, type: T.Type, customizationBlock: ((AskSettings<T>) -> Void)? = nil) -> T {

PromptSettings.print(prompt)

Expand Down
11 changes: 6 additions & 5 deletions Source/ChooseSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum ChoiceIndexType {
public class ChooseSettings<T> {
typealias Item = T

var choices: [(choice: String, callback: (Void) -> T)] = []
var choices: [(choice: String, callback: () -> T)] = []

/// Prompt message to use
public var promptQuestion = ""
Expand All @@ -41,7 +41,7 @@ public class ChooseSettings<T> {
- parameter choice: Item name
- parameter callback: callback called when the item is selected, the value returned from this call back will be returned from choose
*/
public func addChoice(_ choice: String..., callback: @escaping (Void) -> T) {
public func addChoice(_ choice: String..., callback: @escaping () -> T) {
choice.forEach {
choices.append(($0, callback))
}
Expand Down Expand Up @@ -85,14 +85,15 @@ public class ChooseSettings<T> {
}

func preparePromptItems() -> [String] {
return zip(indexChoices(), stringChoices()).map { index, string in
return zip(indexChoices(), stringChoices()).map { pair in
let (index, string) = pair
return "\(index)\(indexSuffix)\(string)"
}
}

func indexChoices() -> [String] {
return stringChoices().enumerated().map { itemIndex, string in

return stringChoices().enumerated().map { pair in
let (itemIndex, _) = pair
if index == .numbers {
return "\(itemIndex + 1)"
} else {
Expand Down
5 changes: 4 additions & 1 deletion Source/Env.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public class Env {
- parameter callback: callback to call on each key/value pair
*/
public static func eachPair(_ callback: (_ key: String, _ value: String) -> ()) {
zip(self.keys, self.values).forEach(callback)
zip(self.keys, self.values).forEach { (pair) in
let (key, value) = pair
callback(key, value)
}
}

}
2 changes: 1 addition & 1 deletion Source/RunResults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func splitCommandToArgs(_ command: String) -> [String] {

func readPipe(_ pipe: TaskPipe) -> String {
let data = pipe.read()
return NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue) as? String ?? ""
return NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue) as String? ?? ""
}
6 changes: 3 additions & 3 deletions Swiftline.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
LastUpgradeCheck = 9999;
TargetAttributes = {
"______Target_Swiftline" = {
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
};
};
Expand Down Expand Up @@ -252,7 +252,7 @@
PRODUCT_BUNDLE_IDENTIFIER = Swiftline;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -269,7 +269,7 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down