Bug in OptionGroup help generation

There is a subtle bug in the OptionGroup help generation.

Given the following application:

struct ParserBug: ParsableCommand {
    static let configuration: CommandConfiguration = CommandConfiguration(
        commandName: "parserBug",
        subcommands: [Sub.self])

    func run() throws {
    }
}

which references a sub command named Sub:

extension ParserBug {
    struct Sub: ParsableCommand {
        @OptionGroup() var commonOptions: CommonOptions

        @Argument(help: "Mandatory argument") var argument: String
    }
}

which references a common option group CommonOptions:

extension ParserBug {
    struct CommonOptions: ParsableCommand {
        @Flag(help: "example flag") var example: Bool = false
    }
}

If I now run this application with the parserBug sub -h command, I get the following output:

USAGE: parserBug sub [--example] <argument>

ARGUMENTS:
  <argument>              Mandatory argument 

OPTIONS:
  --example               example flag 
  -h, --help              Show help information.

and this output is completely as expected. I am now making one minor change in Sub:

extension ParserBug {
    struct Sub: ParsableCommand {
        @OptionGroup() var commonOptions: CommonOptions

        @Argument(help: "Mandatory argument")
        var argument: String? // <== Is now optional
    }
}

If I now run the help again the USAGE line is wrong:

USAGE: parserBug common-options sub [--example] [<argument>]

ARGUMENTS:
  <argument>              Mandatory argument 

OPTIONS:
  --example               example flag 
  -h, --help              Show help information.

The word common-options should not be in the USAGE line.

I have used version 0.3.2.

1 Like

Huh! Thanks so much for the detailed report — would you mind pasting that in as a new issue on GitHub?

Will do

1 Like
Terms of Service

Privacy Policy

Cookie Policy