Mutually exclusive parameters?

Is there a way to express that a command line tool which declares two parameters expects either one or the other to be passed by the caller? Or does this need to be handled in a validate() method?

1 Like

That’s right — the way to express this right now is to declare both properties as optional, and then use the validate() method to enforce that at most one (or exactly one) is specified.

It would be great to hear your specific use case for this feature, if you wouldn’t mind opening an issue on the repository. Thanks!

1 Like

Thanks, I was mainly looking for a way to use the existing property wrappers so that the generated help would render the parameters as mutually exclusive (i.e. enclosed in brackets and separated by a vertical bar; cf. Utility Conventions, section 8.), but that does not seem to be possible.

1 Like

While exclusive parameters aren't currently supported, you can customize the usage string by specifying your own in the command configuration.

https://swiftpackageindex.com/apple/swift-argument-parser/1.3.1/documentation/argumentparser/commandconfiguration/usage