Fish shell completion script error

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.

Two more items that might or might not be considered bugs in the fish completion script generator:

  • Subcommand name abbreviations are not suggested
  • The (hidden?) help "subcommand" is not suggested

E.g., all of the following are legitimate calls to SAP's math example tool:

> ./math mul 2 3
> ./math help
> ./math help stats
> ./math help stats average

Arguably, mul, help, stats and average should suggested when appropriate.

Parsing strategies are not yet supported by any of the completion script generators.

It wouldn't hurt to create a new issue for that. Your best bet for getting parsing strategies support is to submit your own PR. There is a pending completion PR, so, if you plan to work on completions, comment on that to see if you can spur its merge, to avoid merge conflicts.

Many bugs remain extant, and features lacking, in the completion script generators (the info in Completion problems · Issue #679 · apple/swift-argument-parser · GitHub doesn't list all of the known completion issues, and is vastly out of date, as many of the noted problems have already been fixed, but you can see somewhat the extent of the problems that existed around a year ago).

For some issues with help completions, see:

If your issues with help aren't there, it might be best to add them in a comment to #671.