swift-argument-parser
swift-argument-parser copied to clipboard
[GSoC] CLI design for interactive mode
The following internal functions will serve as the basis for the interactive mode:
Ask
prompt the user for input:
let operand = ask("Please enter operand:", type: Int.self)
? Please enter operan: 1.2
? The type of 1.2 is not Int.
? Please enter operan: 1
Choose
provides possible input for the user to choose from:
let choice = choose("Please select an operator:", choices: ["+", "\", "*", "/"])
1. +
2. -
3. *
4. /
? Please select an operator: +
? Please enter a serial number: 0
? 0 is not in the range of 1...4
? Please select an operator: 1
Providing custom validation for user input
let operand = ask("Please enter operand:", type: Int.self) { num in
guard num != 0 else { throw ValidationError("Input can't be 0!") }
}
? Please enter operan: 0
? Input can't be 0!
? Please enter operan: 1
This issue is posted here as a subtask of the GSoC project for discussion and suggestions.
@KeithBird Now that your prototype is largely implemented, let's look again at the design of these functions. The goal is that these could eventually be exposed as public API, so the design should be separate from their use in this interactive project. What parameters will you need to accomplish that?