<html>
<head></head>
<body>
<p>Hi,</p>
<p>I've been trying to code through CommandLine the options I want my tool accepts, but I find find quite impossible to achieve robustly what I need .</p>
<p>Look, I want the tool accepts a list of arguments in a particular order. For this goal, I know the cl::Positional flag. But, the problem is that the first argument must be one of a set of options. In my case, only the three next commands are possible:<br/>
myTool option1<br/>
myTool option2 arg1 arg2 <br/>
myTool option3 arg1</p>
<p>and I don't want a different order is possible, for instance, this is not permitted:<br/>
myTool arg2 option2 arg1</p>
<p>So, I thought about using an enum for this first argument:</p>
<br/>
<p>enum OptLevel{<br/>
option1, option2, option3<br/>
};<br/>
cl::opt<OptLevel> OptionsLevel(<strong>cl::Positional</strong>, cl::desc("Choose one of these options:"),<br/>
cl::values(<br/>
clEnumVal(option1, "..."),<br/>
clEnumVal(option2, "..."),<br/>
clEnumVal(option3, "..."),<br/>
clEnumValEnd),<br/>
);</p>
<br/>
<p>After that, the rest of arguments are also particular of the option selected as the first argument, i.e, the rest of arguments are related with the first one. So I thought I could independently parse these arguments with:</p>
<p>cl::list<std::string> Argv (cl::ConsumeAfter, cl::desc("<program arguments>..."));</p>
<p>But, doing this when I run:</p>
<p>myTool option1 file.cpp --</p>
<p>I got the next error:<br/>
"error - this positional option will never be matched, because it does not Require a value and a cl::ConsumeAfter option is active!"</p>
<p>So, I modify "OptionsLevelOptionsLevel" including the cl::Required flagThe error is now:<br/>
"option: does not allow a value! option1 specified.<br/>
option: must be specified at least once!<br/>
option: must be specified at least once!<br/>
option: must be specified at least once!"</p>
<p>Then, I decided to use cl::PositionalEatsArgs instead of cl::ConsumeAfter. Then, this is the result:<br/>
"option: does not allow a value! option1 specified."</p>
<p>But, this time, the program continues. However, if I run "myTool option3 arg1 file.cpp --" it gives me a different problem:<br/>
"warning: ../build/arg1: 'linker' input unused<br/>
error: unable to handle compilation, expected exactly one compiler job in ' '"</p>
<p>But the program still goes on.</p>
<p>Is there a way to accomplish what I have explained? I don't want those errors and warnings. </p>
<p>Thanks,</p>
<p>Pedro.</p>
<br/>
<br/>
<br/>
</body>
</html>