property wrappers
tanner0101 opened this issue · 0 comments
tanner0101 commented
Property wrappers could be used to make the CommandSignature
API more Swifty. Here's an idea for how this could look:
struct Cowsay: Command {
struct Signature: CommandSignature {
@Argument(help: "What the cow should say")
var message: String
@Option(short: "e", help: "Change the cow's eyes")
var eyes: String?
@Option(short: "t", help: "Change the cow's tongue")
var tongue: String?
@Flag(help: "uses == for cow's eyes")
var borg: Bool
}
let help = "Prints an ASCII cow with a message"
func run(context: CommandContext, signature: Signature) throws {
print(signature.message) // String
print(signature.eyes) // String?
print(signature.tongue) // String?
print(signature.borg) // Bool
}
}
Here's how this command could be used:
Usage: cowsay <message> [--eyes,-e eyes] [--tongue,-t tongue] [--borg]
Prints an ASCII cow with a message
Arguments:
message What the cow should say
Options:
--eyes, -e Change the cow's eyes
--tongue, -t Change the cow's tongue
Flags:
--borg uses == for cow's eyes