This is opinionated, and certainly not essential. I mention it because some others might like the change, and I imagine that it would be (relatively )easy to implement.
When short option names are available, I would prefer their use in the usage line. Like this:
[I] release> ./repeat-phrase --help
OVERVIEW: Repeat a phrase multiple times.
USAGE: repeat-phrase [-iulh] [-c <count>] [-p <prefix>] <phrase>
ARGUMENTS:
<phrase> Name of person to greet, if any.
OPTIONS:
-i, --include-counter Include a counter with each repetition.
-u, --uppercase Print text in upper case.
-l, --lowercase Print text in lower case.
-c, --count <count> How many times to repeat 'phrase' (default: 2).
-p, --prefix <prefix> A word or two to prefix 'phrase'.
-h, --help Show help information.
Rather than this.
[I] release> ./repeat-phrase --help
OVERVIEW: Repeat a phrase multiple times.
USAGE: repeat-phrase [--include-counter] [--uppercase] [--lowercase] [--count <c ount>] [--prefix <prefix>] <phrase>
ARGUMENTS:
<phrase> The phrase to repeat.
OPTIONS:
-i, --include-counter Include a counter with each repetition.
-u, --uppercase Print text in upper case
-l, --lowercase Print text in lower case.
-c, --count <count> How many times to repeat 'phrase'. (default: 2)
-p, --prefix <prefix> A word or two to prefix 'phrase'.
-h, --help Show help information.
I would also prefer that the usage line line-wrapped:
USAGE: repeat-phrase [--include-counter] [--uppercase] [--lowercase]
[--count <count>] [--prefix <prefix>] <phrase>
or something similar.
Here is the code:
main
struct RepeatPhrase: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Repeat a phrase multiple times.")
@Flag(name: .shortAndLong , help: "Include a counter with each repetition.")
var includeCounter = false
@Flag(name: .shortAndLong, help: "Print text in upper case")
var uppercase = false
@Flag(name: .shortAndLong, help: "Print text in lower case.")
var lowercase = false
@Option(name: .shortAndLong ,help: "How many times to repeat 'phrase'.")
var count: Int = 2
@Option(name: .shortAndLong ,help: "A word or two to prefix 'phrase'.")
var prefix: String?
@Argument(help: "The phrase to repeat.")
var phrase: String
mutating func run() throws {
var text = phrase
if let prefix = prefix { text = "\(prefix) - \(text)" }
text = lowercase ? text.lowercased() : uppercase ? text.uppercased() : text
for i in 1...(max(count, 1)) {
if includeCounter { print("\(i): \(text)") } else { print(text) }
}
}
}
By the way. I think dropping the FLAGS header from the help screen and including flags under OPTIONS was a nice improvement.