|
|
|
@ -717,6 +717,26 @@
|
|
|
|
|
<span id="675">675</span>
|
|
|
|
|
<span id="676">676</span>
|
|
|
|
|
<span id="677">677</span>
|
|
|
|
|
<span id="678">678</span>
|
|
|
|
|
<span id="679">679</span>
|
|
|
|
|
<span id="680">680</span>
|
|
|
|
|
<span id="681">681</span>
|
|
|
|
|
<span id="682">682</span>
|
|
|
|
|
<span id="683">683</span>
|
|
|
|
|
<span id="684">684</span>
|
|
|
|
|
<span id="685">685</span>
|
|
|
|
|
<span id="686">686</span>
|
|
|
|
|
<span id="687">687</span>
|
|
|
|
|
<span id="688">688</span>
|
|
|
|
|
<span id="689">689</span>
|
|
|
|
|
<span id="690">690</span>
|
|
|
|
|
<span id="691">691</span>
|
|
|
|
|
<span id="692">692</span>
|
|
|
|
|
<span id="693">693</span>
|
|
|
|
|
<span id="694">694</span>
|
|
|
|
|
<span id="695">695</span>
|
|
|
|
|
<span id="696">696</span>
|
|
|
|
|
<span id="697">697</span>
|
|
|
|
|
</pre><pre class='rust '>
|
|
|
|
|
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
|
|
|
|
|
|
|
|
|
@ -771,6 +791,8 @@
|
|
|
|
|
<span class='ident'>needs_short_version</span>: <span class='ident'>bool</span>,
|
|
|
|
|
<span class='ident'>required</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='ident'>char</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>blacklist</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -799,6 +821,8 @@
|
|
|
|
|
<span class='ident'>needs_short_version</span>: <span class='boolval'>true</span>,
|
|
|
|
|
<span class='ident'>required</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>blacklist</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -851,6 +875,22 @@
|
|
|
|
|
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>arg</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='ident'>Arg</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>arg_list</span>.<span class='ident'>contains</span>(<span class='ident'>a</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument name must be unique, \"{}\" is already in use"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>arg_list</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>short</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>short_list</span>.<span class='ident'>contains</span>(<span class='ident'>s</span>) {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument short must be unique, -{} is already in use"</span>, <span class='ident'>s</span>);
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>short_list</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>s</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>long</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>long_list</span>.<span class='ident'>contains</span>(<span class='ident'>l</span>) {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument long must be unique, --{} is already in use"</span>, <span class='ident'>l</span>);
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>long_list</span>.<span class='ident'>insert</span>(<span class='ident'>l</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>required</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
@ -974,7 +1014,7 @@
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"FLAGS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>iter</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}\t{}"</span>,
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}\t{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" \t"</span>)},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
|
|
|
@ -984,7 +1024,7 @@
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"OPTIONS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>iter</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}\t\t{}"</span>,
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}{}\t\t{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" <{}>"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>),
|
|
|
|
@ -995,7 +1035,7 @@
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"POSITIONAL ARGUMENTS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>iter</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}\t\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}\t\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|