Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with unconditional remaining properties in subcommands #397

Merged
merged 3 commits into from
Jan 31, 2022

Conversation

natecook1000
Copy link
Member

This extends the current behavior of @Argument array properties defined with the .unconditionalRemaining parsing strategy to work with subcommands, as well. For example, with a command hierarchy like this:

@main
struct Root: ParsableCommand {
    static var configuration: CommandConfiguration {
        .init(subcommands: [Sub.self])
    }

    @Flag var verbose = false
}

struct Sub: ParsableCommand {
    @Argument(parsing: .unconditionalRemaining)
    var remainder: [String] = []

    @OptionGroup var root: Root

    func run() {
        print("Verbose:", root.verbose)
        print("Remainder:", remainder)
    }
}

We want the Sub command to capture any arguments after the subcommand name appears in the command-line arguments. This fix enables the following behavior:

$ root --verbose sub foo --bar
Verbose: true
Remainder: foo --bar
$ root sub foo --bar --verbose 
Verbose: false
Remainder: foo --bar --verbose
$ root --verbose sub foo --bar --verbose 
Verbose: true
Remainder: foo --bar --verbose

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

This changes the behavior of parsing when a subcommand includes an
argument array with an unconditionalRemaining parsing strategy, such
that parsing options stops when the subcommand is encountered, so
that the subcommand can pick up those additional options.
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 changed the title Nate/propagate unconditional remaining Fix issue with unconditional remaining properties in subcommands Jan 31, 2022
@natecook1000 natecook1000 merged commit 1a5b1b3 into main Jan 31, 2022
@natecook1000 natecook1000 deleted the nate/propagate_unconditional_remaining branch January 31, 2022 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant