Skip to content

Conversation

@satoshin21
Copy link

@satoshin21 satoshin21 commented Dec 6, 2019

Hi!
I added isBelong(to: ArgumentParser) method to ArgumentParser.Result.
I think this method is needed to detect which subcommand is executed with optional PositionalArgument.

Like this.

let parser = ArgumentParser(...)
let subParser1 = parser.add(subparser: "sub1")
let optionalArgument1 = local.add(positional: "sub1_arg", kind: String.self, optional: true)
let subParser2 = parser.add(subparser: "sub2")

// which subparser is given?
let result = try! parser.parse(Array(CommandLine.arguments.dropFirst()))

If isBelong(to: ArgumentParser) is implemented, We can detect that.

let result = try! parser.parse(Array(CommandLine.arguments.dropFirst()))

if result.isBelong(to: subParser1) {
    // this command is executed by subParser`1`.
}

Or If you have any idea to detect this without above method, Can you let me know?

@satoshin21 satoshin21 requested a review from aciidgh as a code owner December 6, 2019 17:27
@tomerd
Copy link
Contributor

tomerd commented Aug 24, 2020

thanks for the PR @satoshin21 we are adopting SwiftArgumentParser: #2653 shortly. okay to close?

@satoshin21
Copy link
Author

Thank you for letting me know, @tomerd
I close this PR.

@satoshin21 satoshin21 closed this Aug 25, 2020
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.

2 participants