Hello. I went through all the examples, documentation and, in part, the source code, the list of problems, but nowhere did I find any mention of the following.
For example, I have the following:
app.exe --p1 test --p2 test --p21 false --p22 path
What is the right way to make certain options mandatory while other options are present? For example, --p21 and --p22 are required if --p2 is given. --p2 can be optional.
If such an opportunity is not provided in the project, then perhaps it is worth discussing this idea?
Thank you.
While there's no direct for support for expressing dependencies or mutual exclusion between various options, the idea has been brought up and we'd be open to a design proposal.
What you can do though is use a custom argument parser by passing a ParseArgument<T> to the Argument<T> or Option<T> constructor. Here's an example:

@jonsequitur,
First of all, I want to thank you for your answer - I was thinking in roughly the same direction as you suggested. )))
Secondly, regarding the design proposal. The ability to add options to other options (as children options) immediately suggests itself. By analogy with commands (https://github.com/dotnet/command-line-api/wiki/How-To#add-a-subcommand-or-verb).
Suppose there is such an opportunity. Then it is necessary to check whether the child options are obligatory depending on the obligatory parent option. Roughly speaking, e.g. ChildrenOption.IsRequired equivalent to ParentOption.IsRequired && ChildrenOption.IsRequired.
This would work for mutual dependency. A related problem is mutual exclusion, which I don't think is as easily modeled hierarchically.
Both are achievable using a parseArgument delegate but there hasn't been a concrete API proposal to address them in a less "manual" way.
I wonder if something like this might be workable:
// given...
var x = new Option<int>("-x");
var y = new Option<int>("-y");
// dependency:
x.CannotBeUsedWithout(y);
y.CannotBeUsedWithout(x);
// exclusion:
x.CannotBeUsedWith(y);
Another angle to consider is to use the value of an option to discriminate which options should be considered.
Something like
app.exe file.txt --provider aws-s3 --bucket asd
app.exe file.txt --provider local --path somewhere
In the example above, different values of the option provider add different additional options.
I know it could be solved with commands, but I feel it more of a workaround.
That's a very interesting scenario. (Side note, I think it points to a gap in how ParseArgument<T> works versus how suggestions work, meaning you would have to write code in two places to get these to align correctly.)
As you pointed out, I've recently used commands to solve this:
