It appears that both the help screen generator and the completion generator for fish treat the .singleValue parsing strategy the same as the .upToNextOption. Here is the code:
@main
struct MyColor: ParsableCommand {
@Option(parsing: .upToNextOption, help: .init("Your daughter's favorite colors.", valueName: "color"))
var daughter: [ColorOptions]
@Option(parsing: .singleValue, help: .init("One of your son's favorite colors (can be repeated).", valueName: "color"))
var son: [ColorOptions]
func run() {
print("Your daughter's favorite colors are \(daughter.map(\.rawValue))")
print("Your son's favorite colors are \(son.map(\.rawValue))")
}
}
public enum ColorOptions: String, CaseIterable, ExpressibleByArgument {
case red
case blue
case yellow
public var defaultValueDescription: String {
switch self {
case .red:
return "A red color."
case .blue:
return "A blue color."
case .yellow:
return "A yellow color."
}
}
public var description: String {
switch self {
case .red:
return "A red color."
case .blue:
return "A blue color."
case .yellow:
return "A yellow color."
}
}
}
The daughter and son are the same except for parsing strategy. You can fill the daughter’s array in one go. But you fill the son’s array one argument at a time.
> my-color --daughter red blue --son blue --son yellow
Your daughter's favorite colors are ["red", "blue"]
Your son's favorite colors are ["blue", "yellow"]
Yet the usage line in help treats them the same way, which would confuse most people:
> my-color --help
USAGE: color --daughter <color> ... --son <color> ...
OPTIONS:
--daughter <color> Your daughter's favorite colors. (values: red, blue, yellow)
--son <color> One of your son's favorite colors (can be repeated). (values: red, blue, yellow)
-h, --help Show help information.
For what its worth, I believe that the most common way an option like “–son “ would appear in the usage line (or synopsis in a manual page) is just “–-son ” without the “…”.
Turning to the completion:
The problem is that the fish completion script treats the —daughter the same way that it treats –son. That is, immediately after either, a color will be required. But in the case of –daughter, we would expect the script to keep suggesting colors until the next option.
Assume your curser is at a space or two after red.
> my-color --daughter red
If you type tab should get a suggestion of red, blue or yellow. Instead you get “help”:
my-color --daughter red help
This is completely wrong because there is no help subcommand (I assume that is what it is trying to say).
If you type “y” after “red”, above, you should get “yellow” completed instantly. Instead you just get “y”.
Etc.
Comment:
Apparently an Option property wrapper can have one of 7 different parsing strategies and an Argument property wrapper can have one of 4.
a. Writing a completion script that handles all this properly is not going to be easy.
b. Are all these parsing strategies really needed? Why not just offer two for arrays and maybe even just one for single value options.