jakeheis / SwiftCLI

A powerful framework for developing CLIs in Swift
MIT License
861 stars 72 forks source link

Add support for fallback values in input prompts #89

Closed msanders closed 4 years ago

msanders commented 4 years ago

This allows writing the following:

let proceed = Input.readBool(prompt: "Proceed? [Y/n]: ", defaultValue: true)

It falls back to defaultValue only for empty input. Invalid input is treated the same as it is already (i.e., it's refused until corrected, which matches the behavior of most CLIs).

Existing behavior is the same (no breaking changes).

jakeheis commented 4 years ago

This looks great, thanks for the contribution! Would ideally like to have a test in InputTests.swift before merging this

msanders commented 4 years ago

Thanks, done.