apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.31k stars 311 forks source link

`title` argument passed to nested `@OptionGroup` has no effect #558

Open MaxDesiatov opened 1 year ago

MaxDesiatov commented 1 year ago

@OptionGroup behaves in an unexpected way with nested groups when title: argument value is specified.

ArgumentParser version: 1.2.2 Swift version: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: arm64-apple-macosx13.0

Checklist

Steps to Reproduce

Create a type that has properties using @OptionGroup property wrapper with title: argument passed. Uses this type then as @OptionGroup itself. This top level may specify or not specify its own title: argument, this doesn't make a difference on the observed outcome.

Expected behavior

Nested @OptionGroups have their title: values displayed and options grouped by these titles in help output.

Actual behavior

Nested @OptionGroups don't have their title: values displayed and options grouped by these titles in help output. All of the options are displayed within the top-level group, title: values on nested groups have no effect whatsoever.

natecook1000 commented 1 year ago

Great spot, @MaxDesiatov — it would be great if these could preserve their titles when nested. What do you think the behavior should be if the "parent" option group also includes a title? That is, what should the help look like in this case?

struct A: ParsableArguments {
    @Flag var one = false
    @Flag var two = false
}

struct B: ParsableArguments {
    @Flag var three = false
    @Flag var four = false
}

struct Options: ParsableArguments {
    @OptionGroup(title: "Group A")
    var groupA: A

    @OptionGroup(title: "Group B")
    var groupB: B
}

struct Command: ParsableCommand {
    @OptionGroup(title: "All Options")
    var options: Options
}