Swiftline icon indicating copy to clipboard operation
Swiftline copied to clipboard

Unused default values

Open ammerzon opened this issue 7 years ago • 0 comments

I know it is possible to provide default values when prompting the user for input. See below:

let level = ask("Choose level: ", type: Int.self) { settings in
   settings.defaultValue = 1
}

Unfortunately this value is only used in preparedItem() which is not called anywhere. When the user does not provide an input he gets the message to enter a valid integer despite the fact I chose a default value.

public class AskSettings<T: ArgConvertibleType> {
    
    /// Default value to set incase the user entered a blank
    public var defaultValue: T?

    ...

    func preparedItem(originalString string: String) -> T {
        if string.isEmpty && defaultValue != nil {
            return defaultValue!
        }
        
        return T.fromString(string)!
    }
}

ammerzon avatar Apr 19 '17 18:04 ammerzon