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

Unused default values #31

Open
ammerzon opened this issue Apr 19, 2017 · 0 comments
Open

Unused default values #31

ammerzon opened this issue Apr 19, 2017 · 0 comments

Comments

@ammerzon
Copy link

ammerzon commented Apr 19, 2017

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)!
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant