docs(clap): rebuild documentation

This commit is contained in:
Kevin K 2015-04-02 22:49:45 -04:00
parent c238b49ba9
commit 4a057c03c1
8 changed files with 617 additions and 115 deletions

View file

@ -43,7 +43,7 @@
<section id='main' class="content mod">
<h1 class='fqn'><span class='in-band'>Crate <a class='mod' href=''>clap</a><wbr></span><span class='out-of-band'><a href='stability.html'>[stability]</a> <span id='render-detail'>
<a id="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
</span><a id='src-0' href='../src/clap/lib.rs.html#1-272'>[src]</a></span></h1>
</span><a id='src-0' href='../src/clap/lib.rs.html#1-327'>[src]</a></span></h1>
<div class='docblock'>
<h1 id="clap" class='section-header'><a
href="#clap">clap</a></h1>
@ -51,18 +51,74 @@
<p>Command Line Argument Parser written in Rust</p>
<p>It is a simple to use and efficient library for parsing command line arguments and subcommands when writing command line, console, or terminal applications.</p>
<p>It is a simple to use and efficient library for parsing command line arguments and subcommands when writing console, or terminal applications.</p>
<p>You can use clap to lay out a list of possible valid command line arguments and subcommands, then let <code>clap</code> parse <em>and validate</em> the string given by the user at runtime. This means you focus on your applications functionality, not parsing and validating arguments.</p>
<p>You can use <code>clap</code> to lay out a list of possible valid command line arguments and subcommands, then let <code>clap</code> parse <em>and validate</em> the string given by the user at runtime. This means you focus on your applications functionality, not parsing and validating arguments.</p>
<p>What seperates <code>clap</code> from other options available is the very simple almost &#39;Pythonic&#39; style in which you define the valid available arguments for your program. This means you don&#39;t have to spend tons time learning an entirely new library&#39;s structures and use.</p>
<p>What is different about <code>clap</code> from other options available is the very simple almost &#39;Pythonic&#39; style in which you define the valid available arguments for your program, while still giving advanced features. <code>clap</code> allows you express complex relationships between arguments in a very simple manner. This means you don&#39;t have to spend tons time learning an entirely new library&#39;s structures and use. The basics of <code>clap</code> can be learned almost intuitively.</p>
<p><code>clap</code> also provides all the traditional version and help switches (or flags) &#39;for free&#39; by parsing the list of developer supplied arguments. If the developer hasn&#39;t defined them already, <code>clap</code> will auto-generate only the applicable &quot;help&quot; and &quot;version&quot; switches (as well as a &quot;help&quot; subcommand so long as other subcommands have been manually defined as well).</p>
<p><code>clap</code> also provides all the traditional version and help switches (or flags) &#39;for free&#39; by parsing the list of developer supplied arguments. If the developer hasn&#39;t defined them already (or only defined some of them), <code>clap</code> will auto-generate the applicable &quot;help&quot; and &quot;version&quot; switches (as well as a &quot;help&quot; subcommand so long as other subcommands have been manually defined as well).</p>
<p>After defining a list of possible valid arguments and subcommands, <code>clap</code> parses the string given by the end-user at runtime then gives you a list of the valid matches and their values. If the user made an error or typo, <code>clap</code> informs them and exits gracefully. This means that you can simply use these matches and values to determine the functioning of your program.</p>
<h2 id="features" class='section-header'><a
href="#features">Features</a></h2>
<p>Below are a few of the features which <code>clap</code> supports, full descriptions and usage can be found in the <a href="http://kbknapp.github.io/clap-rs/docs/clap/index.html">documentation</a> and <code>examples/</code> directory</p>
<ul>
<li><strong>Auto-generated Help, Version, and Usage information</strong>
<ul>
<li>Can be fully, or partially overridden if you wish to roll your own help, version, or usage</li>
</ul></li>
<li><strong>Flags / Switches</strong> (i.e. bool fields)
<ul>
<li>Both short and long versions supported (i.e. <code>-f</code> and <code>--flag</code> respectively)</li>
<li>Supports combining short versions (i.e. <code>-fBgoZ</code> is the same as <code>-f -B -g -o -Z</code>)</li>
<li>Also supports multiple occurrences (i.e. <code>myprog -vvv</code> or <code>myprog -v -v -v</code>)</li>
</ul></li>
<li><strong>Positional Arguments</strong> (i.e. those which are based off an index)
<ul>
<li>Also supports multiple values (i.e. <code>myprog &lt;file&gt;...</code></li>
<li>Supports Specific Value Sets (See below)</li>
</ul></li>
<li><strong>Option Arguments</strong> (i.e. those that take values as options)
<ul>
<li>Both short and long versions supported (i.e. <code>-o value</code> and <code>--option value</code> or <code>--option=value</code> respectively)</li>
<li>Also supports multiple values (i.e. <code>myprog --option &lt;value&gt; --option &lt;othervalue&gt;</code>)</li>
<li>Supports Specific Value Sets (See below)</li>
</ul></li>
<li><strong>Sub-Commands</strong> (i.e. <code>git add &lt;file&gt;</code> where <code>add</code> is a sub-command of <code>git</code>)
<ul>
<li>Support their own sub-arguments, and sub-commands</li>
<li>Get their own auto-generated Help, Version, and Usage independant of parent</li>
</ul></li>
<li><strong>Requirement Rules</strong>: Arguments can optionally define the following types of requirement rules
<ul>
<li>Required by default</li>
<li>Required only if certain arguments are present</li>
<li>Can require other arguments to be present</li>
</ul></li>
<li><strong>Exclusion Rules</strong>: Arguments can optionally define the following types of exclusion rules
<ul>
<li>Can be disallowed when certain arguments are present</li>
<li>Can disallow use of other arguments when present</li>
</ul></li>
<li><strong>Specific Value Sets</strong>: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a <code>--mode</code> option which may <em>only</em> have one of two values <code>fast</code> or <code>slow</code> such as <code>--mode fast</code> or <code>--mode slow</code>)</li>
<li><strong>Default Values</strong>: Although not specifically provided by <code>clap</code> you can achieve this exact functionality from Rust&#39;s <code>Option&lt;&amp;str&gt;.unwrap_or(&quot;some default&quot;)</code> method</li>
<li><strong>Auto Version from Cargo.toml</strong>: <code>clap</code> is fully compatible with Rust&#39;s <code>env!()</code> macro for achieving this functionality. See <code>examples/09_AutoVersion.rs</code> for how to do this (Thanks to <a href="https://github.com/jhelwig">jhelwig</a> for pointing this out)</li>
</ul>
<h2 id="quick-example" class='section-header'><a
href="#quick-example">Quick Example</a></h2><pre id='rust-example-rendered' class='rust '>
href="#quick-example">Quick Example</a></h2>
<p>The following shows a quick example of some of the basic functionality of <code>clap</code>. For more advanced usage, such as requirements, exclusions, multiple values and occurrences see the <a href="http://kbknapp.github.io/clap-rs/docs/clap/index.html">documentation</a> or <code>examples/</code> directory of this repository.</p>
<pre id='rust-example-rendered' class='rust '>
<span class='comment'>// (Full example with comments in examples/01_QuickExample.rs)</span>
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>clap</span>;
<span class='kw'>use</span> <span class='ident'>clap</span>::{<span class='ident'>Arg</span>, <span class='ident'>App</span>, <span class='ident'>SubCommand</span>};
@ -158,43 +214,77 @@ SUBCOMMANDS:
<span class='ident'>git</span> <span class='op'>=</span> <span class='string'>&quot;https://github.com/kbknapp/clap-rs.git&quot;</span>
</pre>
<p>Then run <code>cargo build</code> or <code>cargo update</code> for your project.</p>
<h2 id="usage" class='section-header'><a
href="#usage">Usage</a></h2>
<p>Add <code>extern crate clap;</code> to your crate root.</p>
<p>Define a list of valid arguments for your program (see the documentation or examples/ directory)</p>
<p>Then run <code>cargo build</code> or <code>cargo update &amp;&amp; cargo build</code> for your project.</p>
<h2 id="more-information" class='section-header'><a
href="#more-information">More Information</a></h2>
<p>You can find complete documentation on the <a href="http://kbknapp.github.io/clap-rs/docs/clap/index.html">github-pages site</a> for this project.</p>
<p>You can also find full usage examples in the examples/ directory of this repo.</p>
<p>You can also find full usage examples in the <code>examples/</code> directory of this repo.</p>
<h2 id="how-to-build" class='section-header'><a
href="#how-to-build">How to build</a></h2>
<p>Clone the repo (<code>master</code> branch if using <code>clap</code>, <code>dev</code> branch if contributing) and build with Cargo</p>
<pre id='rust-example-rendered' class='rust '>
<span class='ident'>git</span> <span class='ident'>clone</span> <span class='ident'>https</span>:<span class='comment'>//github.com/kbknapp/clap-rs</span>
<span class='ident'>cd</span> <span class='ident'>clap</span><span class='op'>-</span><span class='ident'>rs</span>
<span class='ident'>cargo</span> <span class='ident'>build</span> <span class='op'>-</span><span class='op'>-</span><span class='ident'>release</span>
</pre>
<h2 id="how-to-build-and-contribute" class='section-header'><a
href="#how-to-build-and-contribute">How to build and contribute</a></h2>
<p>Contributions are always welcome! And there is a multitude of ways in which you can help depending on what you like to do, or are good at. Anything from documentation, code cleanup, issue completion, new features, you name it, even filing issues is contributing and greatly appreciated!</p>
<ol>
<li>Fork the project</li>
<li>Clone your fork (<code>git clone https://github.com/$USER/clap-rs &amp;&amp; cd clap-rs</code>)</li>
<li>Create new branch (<code>git checkout -b your-branch</code>)</li>
<li>Make your changes, and commit (<code>git commit -am &quot;your message&quot;</code>)</li>
<li>If applicable, run the tests (See below)</li>
<li>Push your changes back to your fork (<code>git push origin your-branch</code>)</li>
<li>Create a pull request! (You can create the pull request right away, and we&#39;ll merge when read. This a good way to discuss proposed changes)</li>
</ol>
<p>Another really great way to help is if you find an interesting, or helpful way in which to use <code>clap</code> you can either add it to the <code>examples/</code> directory, or file an issue and tell me. I&#39;m all about giving credit where credit is due :)</p>
<h3 id="running-the-tests" class='section-header'><a
href="#running-the-tests">Running the tests</a></h3>
<p>If contributing, you can run the tests as follows (assuming you&#39;ve already cloned the repo to <code>clap-rs/</code></p>
<pre id='rust-example-rendered' class='rust '>
<span class='ident'>cd</span> <span class='ident'>clap</span><span class='op'>-</span><span class='ident'>rs</span><span class='op'>/</span><span class='ident'>claptests</span>
<span class='ident'>cd</span> <span class='ident'>clap</span><span class='op'>-</span><span class='ident'>rs</span>
<span class='ident'>cargo</span> <span class='ident'>test</span>
<span class='ident'>cd</span> <span class='ident'>claptests</span>
<span class='ident'>make</span> <span class='ident'>test</span>
</pre>
<h3 id="building-the-documentation" class='section-header'><a
href="#building-the-documentation">Building the documentation</a></h3>
<p>Run this instead of <code>cargo doc</code> to generate the proper module docstring:</p>
<p>If the changes require re-building the documentation, run this instead of <code>cargo doc</code> to generate the proper module docstring:</p>
<pre id='rust-example-rendered' class='rust '>
<span class='ident'>make</span> <span class='ident'>doc</span>
</pre>
<p>Then browse to <code>clap-rs/docs/index.html</code> in your web-browser of choice</p>
<p>Then browse to <code>clap-rs/docs/clap/index.html</code> in your web-browser of choice to check it out. You can then create a PR on the <code>gh-pages</code> branch</p>
<h3 id="goals" class='section-header'><a
href="#goals">Goals</a></h3>
<p>There are a few goals of <code>clap</code> that I&#39;d like to maintain. If your proposed changes break, or go against any of these goals we&#39;ll discuss the changes further before merging (but will <em>not</em> be ignored, all contributes are welcome!). These are by no means hard-and-fast rules, as I&#39;m no expert and break them myself from time to time (even if just by mistake or ignorance :P).</p>
<ul>
<li>Remain backwards compatible when possible
<ul>
<li>If backwards compatibility <em>must</em> be broken, use deprecation warnings if at all possible before removing legacy code</li>
<li>This does not apply for security concerns</li>
</ul></li>
<li>Parse arguments quickly
<ul>
<li>Parsing of arguments shouldn&#39;t slow down usage of the main program</li>
<li>This is also true of generating help and usage information</li>
</ul></li>
<li>Try not to be cognizant of memory usage
<ul>
<li>Once parsing is complete, the memory footprint of <code>clap</code> should be low since the main program is the star of the show</li>
</ul></li>
<li><code>panic!</code> on <em>developer</em> error, exit gracefully on <em>end-user</em> error</li>
</ul>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr>

View file

@ -43,7 +43,7 @@
<section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>App</a><wbr></span><span class='out-of-band'><span id='render-detail'>
<a id="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
</span><a id='src-33' href='../src/clap/app.rs.html#39-65'>[src]</a></span></h1>
</span><a id='src-33' href='../src/clap/app.rs.html#39-66'>[src]</a></span></h1>
<pre class='rust struct'>pub struct App&lt;'a, 'v, 'ab, 'u, 'ar&gt; {
// some fields omitted
}</pre><div class='docblock'><p>Used to create a representation of the program and all possible command line arguments

View file

@ -43,7 +43,7 @@
<section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>Arg</a><wbr></span><span class='out-of-band'><span id='render-detail'>
<a id="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
</span><a id='src-7315' href='../src/clap/args/arg.rs.html#21-55'>[src]</a></span></h1>
</span><a id='src-8174' href='../src/clap/args/arg.rs.html#21-55'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Arg&lt;'n, 'l, 'h, 'b, 'p, 'r&gt; {
pub name: &amp;'n <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>,
pub short: <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a>&lt;<a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a>&gt;,

View file

@ -43,7 +43,7 @@
<section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>ArgMatches</a><wbr></span><span class='out-of-band'><span id='render-detail'>
<a id="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
</span><a id='src-7896' href='../src/clap/args/argmatches.rs.html#62-68'>[src]</a></span></h1>
</span><a id='src-8755' href='../src/clap/args/argmatches.rs.html#62-68'>[src]</a></span></h1>
<pre class='rust struct'>pub struct ArgMatches&lt;'a&gt; {
pub flags: <a class='struct' href='http://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html' title='std::collections::hash::map::HashMap'>HashMap</a>&lt;&amp;'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>, FlagArg&gt;,
pub opts: <a class='struct' href='http://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html' title='std::collections::hash::map::HashMap'>HashMap</a>&lt;&amp;'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>, OptArg&gt;,

View file

@ -43,7 +43,7 @@
<section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>SubCommand</a><wbr></span><span class='out-of-band'><span id='render-detail'>
<a id="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
</span><a id='src-8320' href='../src/clap/args/subcommand.rs.html#23-26'>[src]</a></span></h1>
</span><a id='src-9179' href='../src/clap/args/subcommand.rs.html#23-26'>[src]</a></span></h1>
<pre class='rust struct'>pub struct SubCommand&lt;'a&gt; {
pub name: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a>,
pub matches: <a class='struct' href='../clap/struct.ArgMatches.html' title='clap::ArgMatches'>ArgMatches</a>&lt;'a&gt;,

View file

@ -493,6 +493,10 @@ h1 .stability {
.stability.Locked { border-color: #0084B6; color: #00668c; }
.stability.Unmarked { border-color: #BBBBBB; }
td.summary-column {
width: 100%;
}
.summary {
padding-right: 0px;
}

View file

@ -1130,6 +1130,155 @@
<span id="1088">1088</span>
<span id="1089">1089</span>
<span id="1090">1090</span>
<span id="1091">1091</span>
<span id="1092">1092</span>
<span id="1093">1093</span>
<span id="1094">1094</span>
<span id="1095">1095</span>
<span id="1096">1096</span>
<span id="1097">1097</span>
<span id="1098">1098</span>
<span id="1099">1099</span>
<span id="1100">1100</span>
<span id="1101">1101</span>
<span id="1102">1102</span>
<span id="1103">1103</span>
<span id="1104">1104</span>
<span id="1105">1105</span>
<span id="1106">1106</span>
<span id="1107">1107</span>
<span id="1108">1108</span>
<span id="1109">1109</span>
<span id="1110">1110</span>
<span id="1111">1111</span>
<span id="1112">1112</span>
<span id="1113">1113</span>
<span id="1114">1114</span>
<span id="1115">1115</span>
<span id="1116">1116</span>
<span id="1117">1117</span>
<span id="1118">1118</span>
<span id="1119">1119</span>
<span id="1120">1120</span>
<span id="1121">1121</span>
<span id="1122">1122</span>
<span id="1123">1123</span>
<span id="1124">1124</span>
<span id="1125">1125</span>
<span id="1126">1126</span>
<span id="1127">1127</span>
<span id="1128">1128</span>
<span id="1129">1129</span>
<span id="1130">1130</span>
<span id="1131">1131</span>
<span id="1132">1132</span>
<span id="1133">1133</span>
<span id="1134">1134</span>
<span id="1135">1135</span>
<span id="1136">1136</span>
<span id="1137">1137</span>
<span id="1138">1138</span>
<span id="1139">1139</span>
<span id="1140">1140</span>
<span id="1141">1141</span>
<span id="1142">1142</span>
<span id="1143">1143</span>
<span id="1144">1144</span>
<span id="1145">1145</span>
<span id="1146">1146</span>
<span id="1147">1147</span>
<span id="1148">1148</span>
<span id="1149">1149</span>
<span id="1150">1150</span>
<span id="1151">1151</span>
<span id="1152">1152</span>
<span id="1153">1153</span>
<span id="1154">1154</span>
<span id="1155">1155</span>
<span id="1156">1156</span>
<span id="1157">1157</span>
<span id="1158">1158</span>
<span id="1159">1159</span>
<span id="1160">1160</span>
<span id="1161">1161</span>
<span id="1162">1162</span>
<span id="1163">1163</span>
<span id="1164">1164</span>
<span id="1165">1165</span>
<span id="1166">1166</span>
<span id="1167">1167</span>
<span id="1168">1168</span>
<span id="1169">1169</span>
<span id="1170">1170</span>
<span id="1171">1171</span>
<span id="1172">1172</span>
<span id="1173">1173</span>
<span id="1174">1174</span>
<span id="1175">1175</span>
<span id="1176">1176</span>
<span id="1177">1177</span>
<span id="1178">1178</span>
<span id="1179">1179</span>
<span id="1180">1180</span>
<span id="1181">1181</span>
<span id="1182">1182</span>
<span id="1183">1183</span>
<span id="1184">1184</span>
<span id="1185">1185</span>
<span id="1186">1186</span>
<span id="1187">1187</span>
<span id="1188">1188</span>
<span id="1189">1189</span>
<span id="1190">1190</span>
<span id="1191">1191</span>
<span id="1192">1192</span>
<span id="1193">1193</span>
<span id="1194">1194</span>
<span id="1195">1195</span>
<span id="1196">1196</span>
<span id="1197">1197</span>
<span id="1198">1198</span>
<span id="1199">1199</span>
<span id="1200">1200</span>
<span id="1201">1201</span>
<span id="1202">1202</span>
<span id="1203">1203</span>
<span id="1204">1204</span>
<span id="1205">1205</span>
<span id="1206">1206</span>
<span id="1207">1207</span>
<span id="1208">1208</span>
<span id="1209">1209</span>
<span id="1210">1210</span>
<span id="1211">1211</span>
<span id="1212">1212</span>
<span id="1213">1213</span>
<span id="1214">1214</span>
<span id="1215">1215</span>
<span id="1216">1216</span>
<span id="1217">1217</span>
<span id="1218">1218</span>
<span id="1219">1219</span>
<span id="1220">1220</span>
<span id="1221">1221</span>
<span id="1222">1222</span>
<span id="1223">1223</span>
<span id="1224">1224</span>
<span id="1225">1225</span>
<span id="1226">1226</span>
<span id="1227">1227</span>
<span id="1228">1228</span>
<span id="1229">1229</span>
<span id="1230">1230</span>
<span id="1231">1231</span>
<span id="1232">1232</span>
<span id="1233">1233</span>
<span id="1234">1234</span>
<span id="1235">1235</span>
<span id="1236">1236</span>
<span id="1237">1237</span>
<span id="1238">1238</span>
<span id="1239">1239</span>
</pre><pre class='rust '>
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
@ -1188,6 +1337,7 @@
<span class='ident'>needs_short_version</span>: <span class='ident'>bool</span>,
<span class='ident'>needs_subcmd_help</span>: <span class='ident'>bool</span>,
<span class='ident'>required</span>: <span class='ident'>HashSet</span><span class='op'>&lt;</span><span class='kw-2'>&amp;</span><span class='lifetime'>&#39;ar</span> <span class='ident'>str</span><span class='op'>&gt;</span>,
<span class='ident'>matched_reqs</span>: <span class='ident'>HashSet</span><span class='op'>&lt;</span><span class='kw-2'>&amp;</span><span class='lifetime'>&#39;ar</span> <span class='ident'>str</span><span class='op'>&gt;</span>,
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span><span class='op'>&lt;</span><span class='kw-2'>&amp;</span><span class='lifetime'>&#39;ar</span> <span class='ident'>str</span><span class='op'>&gt;</span>,
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span><span class='op'>&lt;</span><span class='ident'>char</span><span class='op'>&gt;</span>,
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span><span class='op'>&lt;</span><span class='kw-2'>&amp;</span><span class='lifetime'>&#39;ar</span> <span class='ident'>str</span><span class='op'>&gt;</span>,
@ -1224,6 +1374,7 @@
<span class='ident'>needs_subcmd_help</span>: <span class='boolval'>true</span>,
<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'>matched_reqs</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>(),
@ -1349,6 +1500,7 @@
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>takes_value</span> {
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Argument \&quot;{}\&quot; has conflicting requirements, both index() and takes_value(true) were supplied&quot;</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
}
<span class='comment'>// Create the Positional Arguemnt Builder with each HashSet = None to only allocate those that require it</span>
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>pb</span> <span class='op'>=</span> <span class='ident'>PosBuilder</span> {
<span class='ident'>name</span>: <span class='ident'>a</span>.<span class='ident'>name</span>,
@ -1371,7 +1523,8 @@
<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'>r</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>requires</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>rhs</span> <span class='op'>=</span> <span class='ident'>HashSet</span>::<span class='ident'>new</span>();
<span class='comment'>// without derefing n = &amp;&amp;str</span>
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>r</span> { <span class='ident'>rhs</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>n</span>); }
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>r</span> {
<span class='ident'>rhs</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>n</span>); }
<span class='ident'>pb</span>.<span class='ident'>requires</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>rhs</span>);
}
<span class='comment'>// Check if there is anything in the possible values and add those as well</span>
@ -1439,7 +1592,10 @@
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Argument \&quot;{}\&quot; must have either a short() and/or long() supplied since no index() or takes_value() were found&quot;</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
}
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>required</span> {
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Argument \&quot;{}\&quot; cannot be required(true) because it has no index() or takes_value(true)&quot;</span>, <span class='ident'>a</span>.<span class='ident'>name</span>)
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Argument \&quot;{}\&quot; cannot be required(true) because it has no index() or takes_value(true)&quot;</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
}
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>possible_vals</span>.<span class='ident'>is_some</span>() {
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Argument \&quot;{}\&quot; cannot have a specific value set because it doesn&#39;t have takes_value(true) set&quot;</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
}
<span class='comment'>// No need to check for index() or takes_value() as that is handled above</span>
@ -1539,36 +1695,55 @@
}
<span class='kw'>fn</span> <span class='ident'>print_usage</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>more_info</span>: <span class='ident'>bool</span>) {
<span class='kw'>let</span> <span class='ident'>tab</span> <span class='op'>=</span> <span class='string'>&quot; &quot;</span>;
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;USAGE:&quot;</span>);
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>u</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>usage_str</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;\t{}&quot;</span>,<span class='ident'>u</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}&quot;</span>,<span class='ident'>tab</span>,<span class='ident'>u</span>);
} <span class='kw'>else</span> {
<span class='kw'>let</span> <span class='ident'>flags</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='ident'>pos</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='ident'>opts</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='ident'>subcmds</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>num_req_pos</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>let</span> <span class='ident'>req_pos</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>matched_pos_reqs</span> <span class='op'>=</span> <span class='ident'>HashSet</span>::<span class='ident'>new</span>();
<span class='comment'>// If it&#39;s required we also need to ensure all previous positionals are required too</span>
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>false</span>;
<span class='kw'>for</span> <span class='ident'>p</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>rev</span>() {
<span class='kw'>if</span> <span class='ident'>found</span> {
<span class='ident'>matched_pos_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
<span class='kw'>continue</span>;
}
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
<span class='ident'>matched_pos_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
<span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>true</span>;
}
}
<span class='kw'>let</span> <span class='ident'>req_pos</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='ident'>matched_pos_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
<span class='ident'>num_req_pos</span> <span class='op'>+=</span> <span class='number'>1</span>;
<span class='prelude-val'>Some</span>(<span class='ident'>x</span>.<span class='ident'>name</span>)
<span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>multiple</span> {
<span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;&lt;{}&gt;...&quot;</span>, <span class='ident'>x</span>.<span class='ident'>name</span>))
} <span class='kw'>else</span> {
<span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;&lt;{}&gt;&quot;</span>, <span class='ident'>x</span>.<span class='ident'>name</span>))
}
} <span class='kw'>else</span> {
<span class='prelude-val'>None</span>
})
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;&lt;{}&gt; &quot;</span>, <span class='ident'>name</span>)[..]);
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{} &quot;</span>, <span class='ident'>name</span>)[..]);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>num_req_opts</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>let</span> <span class='ident'>req_opts</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
<span class='kw'>let</span> <span class='ident'>req_opts</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
<span class='ident'>num_req_opts</span> <span class='op'>+=</span> <span class='number'>1</span>;
<span class='prelude-val'>Some</span>(<span class='ident'>x</span>)
}<span class='kw'>else</span> {
<span class='prelude-val'>None</span>
})
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>o</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}{} &quot;</span>,<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>short</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{} &quot;</span>, <span class='ident'>s</span>)
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>o</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}{} &quot;</span>,<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>long</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}=&quot;</span>, <span class='ident'>l</span>)
} <span class='kw'>else</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}=&quot;</span>,<span class='ident'>o</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>())
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{} &quot;</span>,<span class='ident'>o</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
},<span class='ident'>o</span>.<span class='ident'>name</span>));
<span class='macro'>print</span><span class='macro'>!</span>(<span class='string'>&quot;\t{} {} {} {} {}&quot;</span>, <span class='self'>self</span>.<span class='ident'>bin_name</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap_or</span>(<span class='self'>self</span>.<span class='ident'>name</span>.<span class='ident'>clone</span>()),
<span class='macro'>print</span><span class='macro'>!</span>(<span class='string'>&quot;{}{} {} {} {} {}&quot;</span>,<span class='ident'>tab</span>, <span class='self'>self</span>.<span class='ident'>bin_name</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap_or</span>(<span class='self'>self</span>.<span class='ident'>name</span>.<span class='ident'>clone</span>()),
<span class='kw'>if</span> <span class='ident'>flags</span> {<span class='string'>&quot;[FLAGS]&quot;</span>} <span class='kw'>else</span> {<span class='string'>&quot;&quot;</span>},
<span class='kw'>if</span> <span class='ident'>opts</span> {
<span class='kw'>if</span> <span class='ident'>num_req_opts</span> <span class='op'>!=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>len</span>() <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='ident'>req_opts</span>.<span class='ident'>is_empty</span>() {
@ -1603,6 +1778,32 @@
<span class='kw'>let</span> <span class='ident'>opts</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='ident'>subcmds</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>is_empty</span>();
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_flag</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>for</span> <span class='ident'>fl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>
.<span class='ident'>values</span>()
.<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='ident'>f</span>.<span class='ident'>long</span>)
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>l</span><span class='op'>|</span> <span class='ident'>l</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span>) {
<span class='kw'>if</span> <span class='ident'>fl</span> <span class='op'>&gt;</span> <span class='ident'>longest_flag</span> { <span class='ident'>longest_flag</span> <span class='op'>=</span> <span class='ident'>fl</span>; }
}
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_opt</span><span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>for</span> <span class='ident'>ol</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>
.<span class='ident'>values</span>()
.<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>() {<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> }; <span class='prelude-val'>Some</span>(<span class='ident'>f</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span> <span class='op'>+</span> <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>3</span>)}<span class='kw'>else</span> {<span class='prelude-val'>None</span>}) {
<span class='kw'>if</span> <span class='ident'>ol</span> <span class='op'>&gt;</span> <span class='ident'>longest_opt</span> {<span class='ident'>longest_opt</span> <span class='op'>=</span> <span class='ident'>ol</span>;}
}
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_pos</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>for</span> <span class='ident'>pl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>
.<span class='ident'>values</span>()
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>multiple</span> { <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>3</span> } <span class='kw'>else</span> { <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() } ) {
<span class='kw'>if</span> <span class='ident'>pl</span> <span class='op'>&gt;</span> <span class='ident'>longest_pos</span> {<span class='ident'>longest_pos</span> <span class='op'>=</span> <span class='ident'>pl</span>;}
}
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_sc</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>for</span> <span class='ident'>scl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>
.<span class='ident'>values</span>()
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() ) {
<span class='kw'>if</span> <span class='ident'>scl</span> <span class='op'>&gt;</span> <span class='ident'>longest_sc</span> {<span class='ident'>longest_sc</span> <span class='op'>=</span> <span class='ident'>scl</span>;}
}
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>author</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>author</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}&quot;</span>, <span class='ident'>author</span>);
}
@ -1614,34 +1815,59 @@
<span class='kw'>if</span> <span class='ident'>flags</span> <span class='op'>||</span> <span class='ident'>opts</span> <span class='op'>||</span> <span class='ident'>pos</span> <span class='op'>||</span> <span class='ident'>subcmds</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;&quot;</span>);
}
<span class='kw'>let</span> <span class='ident'>tab</span> <span class='op'>=</span> <span class='string'>&quot; &quot;</span>;
<span class='kw'>if</span> <span class='ident'>flags</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;FLAGS:&quot;</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'>values</span>() {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;\t{}{}\t{}&quot;</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;-{}&quot;</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()},
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;,--{}&quot;</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='string'>&quot; \t&quot;</span>.<span class='ident'>to_owned</span>()},
<span class='ident'>v</span>.<span class='ident'>help</span>.<span class='ident'>unwrap_or</span>(<span class='string'>&quot; &quot;</span>) );
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}{}{}&quot;</span>,<span class='ident'>tab</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;-{}&quot;</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()},
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;{}--{}{}&quot;</span>,
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>() { <span class='string'>&quot;, &quot;</span> } <span class='kw'>else</span> {<span class='string'>&quot;&quot;</span>},
<span class='ident'>l</span>,
<span class='comment'>// +2 accounts for the &#39;, &#39; +4 for tab = 6</span>
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_flag</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span>)))
} <span class='kw'>else</span> {
<span class='comment'>// 6 is tab (4) + -- (2)</span>
<span class='self'>self</span>.<span class='ident'>get_spaces</span>(<span class='ident'>longest_flag</span><span class='op'>+</span><span class='number'>6</span>).<span class='ident'>to_owned</span>()
},
<span class='ident'>v</span>.<span class='ident'>help</span>.<span class='ident'>unwrap_or</span>(<span class='ident'>tab</span>) );
}
}
<span class='kw'>if</span> <span class='ident'>opts</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;OPTIONS:&quot;</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'>values</span>() {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>needs_tab</span> <span class='op'>=</span> <span class='boolval'>false</span>;
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;\t{}{}{}\t{}&quot;</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;-{} &quot;</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()},
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;,--{}=&quot;</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='ident'>needs_tab</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()},
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}&quot;</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='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}{}&quot;</span>,
<span class='kw'>if</span> <span class='ident'>needs_tab</span> { <span class='string'>&quot;\t&quot;</span> } <span class='kw'>else</span> { <span class='string'>&quot;&quot;</span> },
<span class='ident'>h</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'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; [values:{}]&quot;</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}&quot;</span>,<span class='ident'>name</span>)[..] ))
}<span class='kw'>else</span>{<span class='string'>&quot;&quot;</span>.<span class='ident'>to_owned</span>()})
<span class='comment'>// if it supports multiple we add &#39;...&#39; i.e. 3 to the name length</span>
<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> };
<span class='comment'>// let long_len = if v.long.is_some() { v.long.unwrap().len() + 3}else{0};</span>
<span class='comment'>// let mut needs_tab = false;</span>
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}{}{}{}{}&quot;</span>,<span class='ident'>tab</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;-{}&quot;</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()},
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</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'>&quot;{}--{}=&quot;</span>,
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>() {<span class='string'>&quot;, &quot;</span>} <span class='kw'>else</span> {<span class='string'>&quot;&quot;</span>},<span class='ident'>l</span>)
} <span class='kw'>else</span> {
<span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()
<span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()
},
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}&quot;</span>, <span class='ident'>v</span>.<span class='ident'>name</span>, <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span>{<span class='string'>&quot;...&quot;</span>} <span class='kw'>else</span> {<span class='string'>&quot;&quot;</span>}),
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>() {
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_opt</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span> <span class='op'>+</span> <span class='ident'>mult</span>))
} <span class='kw'>else</span> {
<span class='comment'>// 7 is &#39;--=&#39; (3) + tab (4)</span>
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_opt</span> <span class='op'>+</span> <span class='number'>6</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span>))
},
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}&quot;</span>, <span class='ident'>h</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'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; [values:{}]&quot;</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] ))
}<span class='kw'>else</span>{
<span class='string'>&quot;&quot;</span>.<span class='ident'>to_owned</span>()
})
} <span class='kw'>else</span> {
<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()
} );
}
}
@ -1649,30 +1875,66 @@
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;POSITIONAL ARGUMENTS:&quot;</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'>values</span>() {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;\t{}\t\t{}&quot;</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='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}&quot;</span>,
<span class='ident'>h</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'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; [values:{}]&quot;</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] ))
}<span class='kw'>else</span>{<span class='string'>&quot;&quot;</span>.<span class='ident'>to_owned</span>()})
} <span class='kw'>else</span> {
<span class='string'>&quot; &quot;</span>.<span class='ident'>to_owned</span>()
} );
<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> };
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}{}{}&quot;</span>,<span class='ident'>tab</span>,
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}...&quot;</span>,<span class='ident'>v</span>.<span class='ident'>name</span>)} <span class='kw'>else</span> {<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>()},
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_pos</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span>)),
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}&quot;</span>,
<span class='ident'>h</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'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; [values:{}]&quot;</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] ))
}<span class='kw'>else</span>{<span class='string'>&quot;&quot;</span>.<span class='ident'>to_owned</span>()})
} <span class='kw'>else</span> {
<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()
} );
}
}
<span class='kw'>if</span> <span class='ident'>subcmds</span> {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;SUBCOMMANDS:&quot;</span>);
<span class='kw'>for</span> <span class='ident'>sc</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>values</span>() {
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;\t{}\t\t{}&quot;</span>, <span class='ident'>sc</span>.<span class='ident'>name</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>) <span class='op'>=</span> <span class='ident'>sc</span>.<span class='ident'>about</span> {<span class='ident'>a</span>} <span class='kw'>else</span> {<span class='string'>&quot; &quot;</span>} );
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;{}{}{}{}&quot;</span>,<span class='ident'>tab</span>,
<span class='ident'>sc</span>.<span class='ident'>name</span>,
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_sc</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>sc</span>.<span class='ident'>name</span>.<span class='ident'>len</span>())),
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>) <span class='op'>=</span> <span class='ident'>sc</span>.<span class='ident'>about</span> {<span class='ident'>a</span>} <span class='kw'>else</span> {<span class='ident'>tab</span>} );
}
}
<span class='self'>self</span>.<span class='ident'>exit</span>();
}
<span class='attribute'>#[<span class='ident'>inline</span>(<span class='ident'>always</span>)]</span>
<span class='kw'>fn</span> <span class='ident'>get_spaces</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>num</span>: <span class='ident'>usize</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>str</span> {
<span class='kw'>match</span> <span class='ident'>num</span> {
<span class='number'>0</span> <span class='op'>=&gt;</span> <span class='string'>&quot;&quot;</span>,
<span class='number'>1</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>2</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>3</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>4</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>5</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>6</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>7</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>8</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>9</span> <span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>10</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>11</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>12</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>13</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>14</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>15</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>16</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>17</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>18</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>19</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>20</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>21</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>22</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>23</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>24</span><span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>,
<span class='number'>25</span><span class='op'>|</span>_<span class='op'>=&gt;</span> <span class='string'>&quot; &quot;</span>
}
}
<span class='kw'>fn</span> <span class='ident'>print_version</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>quit</span>: <span class='ident'>bool</span>) {
<span class='comment'>// Print the binary name if existing, but replace all spaces with hyphens in case we&#39;re</span>
<span class='comment'>// dealing with subcommands i.e. git mv is translated to git-mv</span>
@ -1692,7 +1954,7 @@
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_matches</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>ArgMatches</span><span class='op'>&lt;</span><span class='lifetime'>&#39;ar</span><span class='op'>&gt;</span> {
<span class='self'>self</span>.<span class='ident'>verify_positionals</span>();
<span class='kw'>for</span> <span class='ident'>sc</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>values</span>() {
<span class='kw'>for</span> (_,<span class='ident'>sc</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>iter_mut</span>() {
<span class='ident'>sc</span>.<span class='ident'>verify_positionals</span>();
}
@ -1713,7 +1975,7 @@
<span class='ident'>matches</span>
}
<span class='kw'>fn</span> <span class='ident'>verify_positionals</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) {
<span class='kw'>fn</span> <span class='ident'>verify_positionals</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
<span class='comment'>// Because you must wait until all arguments have been supplied, this is the first chance</span>
<span class='comment'>// to make assertions on positional argument indexes</span>
<span class='comment'>// </span>
@ -1734,6 +1996,19 @@
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>&quot;Found positional argument \&quot;{}\&quot; which accepts multiple values but it&#39;s not the last positional argument (i.e. others have a higher index)&quot;</span>,
<span class='ident'>p</span>.<span class='ident'>name</span>);
}
<span class='comment'>// If it&#39;s required we also need to ensure all previous positionals are required too</span>
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>false</span>;
<span class='kw'>for</span> (_, <span class='ident'>p</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>iter_mut</span>().<span class='ident'>rev</span>() {
<span class='kw'>if</span> <span class='ident'>found</span> {
<span class='ident'>p</span>.<span class='ident'>required</span> <span class='op'>=</span> <span class='boolval'>true</span>;
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
<span class='kw'>continue</span>;
}
<span class='kw'>if</span> <span class='ident'>p</span>.<span class='ident'>required</span> {
<span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>true</span>;
}
}
}
<span class='kw'>fn</span> <span class='ident'>get_matches_from</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>matches</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>ArgMatches</span><span class='op'>&lt;</span><span class='lifetime'>&#39;ar</span><span class='op'>&gt;</span>, <span class='ident'>it</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>IntoIter</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>) {
@ -1759,12 +2034,13 @@
}<span class='kw'>else</span>{
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}&quot;</span>, <span class='ident'>opt</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
},
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n\t[valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n [valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</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='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>get_mut</span>(<span class='ident'>opt</span>.<span class='ident'>name</span>) {
<span class='ident'>o</span>.<span class='ident'>values</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
<span class='comment'>// if it&#39;s multiple the occurrences are increased when originall found</span>
<span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>opt</span>.<span class='ident'>multiple</span> { <span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>+</span> <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>1</span> };
}
@ -1776,6 +2052,7 @@
<span class='ident'>needs_val_of</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
<span class='kw'>continue</span>;
}
<span class='kw'>if</span> <span class='ident'>arg_slice</span>.<span class='ident'>starts_with</span>(<span class='string'>&quot;--&quot;</span>) <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='ident'>pos_only</span> {
<span class='kw'>if</span> <span class='ident'>arg_slice</span>.<span class='ident'>len</span>() <span class='op'>==</span> <span class='number'>2</span> {
<span class='ident'>pos_only</span> <span class='op'>=</span> <span class='boolval'>true</span>;
@ -1800,9 +2077,12 @@
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;Found positional argument {}, but {} doesn&#39;t accept any&quot;</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
<span class='comment'>// If we find that an argument requires a positiona, we need to update all the</span>
<span class='comment'>// previous positionals too. This will denote where to start</span>
<span class='comment'>// let mut req_pos_from_name = None;</span>
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>p</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>get</span>(<span class='kw-2'>&amp;</span><span class='ident'>pos_counter</span>) {
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument \&quot;{}\&quot; is mutually exclusive with one or more other arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument \&quot;{}\&quot; cannot be used with one or more of the other specified arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
@ -1812,7 +2092,7 @@
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\&quot;{}\&quot; isn&#39;t a valid value for {}{}&quot;</span>,
<span class='ident'>arg_slice</span>,
<span class='ident'>p</span>.<span class='ident'>name</span>,
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n\t[valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n [valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
}
}
@ -1841,15 +2121,19 @@
<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'>bl</span>) <span class='op'>=</span> <span class='ident'>p</span>.<span class='ident'>blacklist</span> {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
}
}
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
<span class='comment'>// No need to check for existance, returns None if not found</span>
<span class='comment'>// if self.required.contains(p.name) {</span>
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
}
<span class='comment'>// }</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'>reqs</span>) <span class='op'>=</span> <span class='ident'>p</span>.<span class='ident'>requires</span> {
<span class='comment'>// Add all required args which aren&#39;t already found in matches to the</span>
<span class='comment'>// final required list</span>
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
@ -1870,12 +2154,14 @@
}
_ <span class='op'>=&gt;</span> {}
}
<span class='self'>self</span>.<span class='ident'>validate_blacklist</span>(<span class='kw-2'>&amp;</span><span class='ident'>matches</span>);
<span class='kw'>if</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>is_empty</span>() {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='string'>&quot;One or more required arguments were not supplied&quot;</span>.<span class='ident'>to_owned</span>(),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
<span class='self'>self</span>.<span class='ident'>validate_blacklist</span>(<span class='kw-2'>&amp;</span><span class='ident'>matches</span>);
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>sc_name</span>) <span class='op'>=</span> <span class='ident'>subcmd_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='kw-2'>mut</span> <span class='ident'>sc</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>get_mut</span>(<span class='kw-2'>&amp;</span><span class='ident'>sc_name</span>) {
@ -1950,7 +2236,7 @@
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
<span class='comment'>// Ensure this option isn&#39;t on the master mutually excludes list</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument --{} is mutually exclusive with one or more other arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument --{} cannot be used with one or more of the other specified arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
@ -1968,7 +2254,7 @@
}<span class='kw'>else</span>{
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}&quot;</span>, <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
},
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n\t[valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\n [valid values:{}]&quot;</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&amp;</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot; {}&quot;</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
}
}
@ -1981,7 +2267,6 @@
} <span class='kw'>else</span> {
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
<span class='comment'>// If arg_val is None occurrences will get incremented upon receiving a value</span>
<span class='ident'>occurrences</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>0</span> },
<span class='ident'>values</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</span>()]} <span class='kw'>else</span> {<span class='macro'>vec</span><span class='macro'>!</span>[]}
});
@ -1990,15 +2275,18 @@
<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'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
}
}
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='comment'>// No need to check for existance, returns None if not found</span>
<span class='comment'>// if self.required.contains(v.name) {</span>
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
}
<span class='comment'>// }</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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
<span class='comment'>// Add all required args which aren&#39;t already found in matches to the</span>
<span class='comment'>// final required list</span>
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
@ -2015,7 +2303,7 @@
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
<span class='comment'>// Ensure this flag isn&#39;t on the mutually excludes list</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument --{} is mutually exclusive with one or more other arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument --{} cannot be used with one or more of the other specified arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
@ -2039,20 +2327,23 @@
<span class='comment'>// If this flag was requierd, remove it</span>
<span class='comment'>// .. even though Flags shouldn&#39;t be required</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='comment'>// No need to check for existance, returns None if not found</span>
<span class='comment'>// if self.required.contains(v.name) {</span>
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
}
<span class='comment'>// }</span>
<span class='comment'>// Add all of this flags &quot;mutually excludes&quot; list to the master list</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'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
}
}
<span class='comment'>// Add all required args which aren&#39;t already found in matches to the master list</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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
@ -2094,7 +2385,7 @@
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg_c</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
<span class='comment'>// Ensure this option isn&#39;t on the master mutually excludes list</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument --{} is mutually exclusive with one or more other arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument -{} cannot be used with one or more of the other specified arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
@ -2105,7 +2396,7 @@
} <span class='kw'>else</span> {
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
<span class='comment'>// occurrences will get incremented upon receiving a value</span>
<span class='comment'>// occurrences will be incremented on getting a value</span>
<span class='ident'>occurrences</span>: <span class='number'>0</span>,
<span class='ident'>values</span>: <span class='macro'>vec</span><span class='macro'>!</span>[]
});
@ -2113,15 +2404,18 @@
<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'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
}
}
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='comment'>// No need to check for existance, returns None if not found</span>
<span class='comment'>// if self.required.contains(v.name) {</span>
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
}
<span class='comment'>// }</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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
<span class='comment'>// Add all required args which aren&#39;t already found in matches to the</span>
<span class='comment'>// final required list</span>
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
@ -2142,7 +2436,7 @@
<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'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&amp;</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>) {
<span class='comment'>// Ensure this flag isn&#39;t on the mutually excludes list</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument -{} is mutually exclusive with one or more other arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument -{} cannot be used with one or more of the other specified arguments&quot;</span>, <span class='ident'>arg</span>),
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
@ -2165,20 +2459,24 @@
<span class='comment'>// If this flag was requierd, remove it</span>
<span class='comment'>// .. even though Flags shouldn&#39;t be required</span>
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
<span class='comment'>// No need to check for existance, returns None if it didn&#39;t exist</span>
<span class='comment'>// if self.required.contains(v.name) {</span>
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
}
<span class='comment'>// }</span>
<span class='comment'>// Add all of this flags &quot;mutually excludes&quot; list to the master list</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'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
}
}
<span class='comment'>// Add all required args which aren&#39;t already found in matches to the master list</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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
@ -2194,7 +2492,7 @@
<span class='kw'>fn</span> <span class='ident'>validate_blacklist</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>matches</span>: <span class='kw-2'>&amp;</span><span class='ident'>ArgMatches</span><span class='op'>&lt;</span><span class='lifetime'>&#39;ar</span><span class='op'>&gt;</span>) {
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>iter</span>() {
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument {} is mutually exclusive with one or more other arguments&quot;</span>,
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument {} cannot be used with one or more of the other specified arguments&quot;</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}&quot;</span>, <span class='ident'>s</span>)
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
@ -2204,17 +2502,17 @@
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument {} is mutually exclusive with one or more other arguments&quot;</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}&quot;</span>, <span class='ident'>s</span>)
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;--{}&quot;</span>, <span class='ident'>l</span>)
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument {} cannot be used with one or more of the other specified arguments&quot;</span>,
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;--{}&quot;</span>, <span class='ident'>s</span>)
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;-{}&quot;</span>, <span class='ident'>l</span>)
} <span class='kw'>else</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;\&quot;{}\&quot;&quot;</span>, <span class='ident'>name</span>)
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
}
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument \&quot;{}\&quot; is mutually exclusive with one or more other arguments&quot;</span>,<span class='ident'>name</span>),
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;The argument \&quot;{}\&quot; cannot be used with one or more of the other specified arguments&quot;</span>,<span class='ident'>name</span>),
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
}
}

View file

@ -312,6 +312,61 @@
<span id="270">270</span>
<span id="271">271</span>
<span id="272">272</span>
<span id="273">273</span>
<span id="274">274</span>
<span id="275">275</span>
<span id="276">276</span>
<span id="277">277</span>
<span id="278">278</span>
<span id="279">279</span>
<span id="280">280</span>
<span id="281">281</span>
<span id="282">282</span>
<span id="283">283</span>
<span id="284">284</span>
<span id="285">285</span>
<span id="286">286</span>
<span id="287">287</span>
<span id="288">288</span>
<span id="289">289</span>
<span id="290">290</span>
<span id="291">291</span>
<span id="292">292</span>
<span id="293">293</span>
<span id="294">294</span>
<span id="295">295</span>
<span id="296">296</span>
<span id="297">297</span>
<span id="298">298</span>
<span id="299">299</span>
<span id="300">300</span>
<span id="301">301</span>
<span id="302">302</span>
<span id="303">303</span>
<span id="304">304</span>
<span id="305">305</span>
<span id="306">306</span>
<span id="307">307</span>
<span id="308">308</span>
<span id="309">309</span>
<span id="310">310</span>
<span id="311">311</span>
<span id="312">312</span>
<span id="313">313</span>
<span id="314">314</span>
<span id="315">315</span>
<span id="316">316</span>
<span id="317">317</span>
<span id="318">318</span>
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
</pre><pre class='rust '>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>crate_type</span><span class='op'>=</span> <span class='string'>&quot;lib&quot;</span>]</span>
@ -324,18 +379,51 @@
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Command Line Argument Parser written in Rust</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! It is a simple to use and efficient library for parsing command line arguments and subcommands when writing command line, console, or terminal applications.</span>
<span class='doccomment'>//! It is a simple to use and efficient library for parsing command line arguments and subcommands when writing console, or terminal applications.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! You can use clap to lay out a list of possible valid command line arguments and subcommands, then let `clap` parse *and validate* the string given by the user at runtime. This means you focus on your applications functionality, not parsing and validating arguments.</span>
<span class='doccomment'>//! You can use `clap` to lay out a list of possible valid command line arguments and subcommands, then let `clap` parse *and validate* the string given by the user at runtime. This means you focus on your applications functionality, not parsing and validating arguments.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! What seperates `clap` from other options available is the very simple almost &#39;Pythonic&#39; style in which you define the valid available arguments for your program. This means you don&#39;t have to spend tons time learning an entirely new library&#39;s structures and use.</span>
<span class='doccomment'>//! What is different about `clap` from other options available is the very simple almost &#39;Pythonic&#39; style in which you define the valid available arguments for your program, while still giving advanced features. `clap` allows you express complex relationships between arguments in a very simple manner. This means you don&#39;t have to spend tons time learning an entirely new library&#39;s structures and use. The basics of `clap` can be learned almost intuitively.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! `clap` also provides all the traditional version and help switches (or flags) &#39;for free&#39; by parsing the list of developer supplied arguments. If the developer hasn&#39;t defined them already, `clap` will auto-generate only the applicable &quot;help&quot; and &quot;version&quot; switches (as well as a &quot;help&quot; subcommand so long as other subcommands have been manually defined as well).</span>
<span class='doccomment'>//! `clap` also provides all the traditional version and help switches (or flags) &#39;for free&#39; by parsing the list of developer supplied arguments. If the developer hasn&#39;t defined them already (or only defined some of them), `clap` will auto-generate the applicable &quot;help&quot; and &quot;version&quot; switches (as well as a &quot;help&quot; subcommand so long as other subcommands have been manually defined as well).</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! After defining a list of possible valid arguments and subcommands, `clap` parses the string given by the end-user at runtime then gives you a list of the valid matches and their values. If the user made an error or typo, `clap` informs them and exits gracefully. This means that you can simply use these matches and values to determine the functioning of your program.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## Features</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Below are a few of the features which `clap` supports, full descriptions and usage can be found in the [documentation](http://kbknapp.github.io/clap-rs/docs/clap/index.html) and `examples/` directory</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! * **Auto-generated Help, Version, and Usage information**</span>
<span class='doccomment'>//! - Can be fully, or partially overridden if you wish to roll your own help, version, or usage</span>
<span class='doccomment'>//! * **Flags / Switches** (i.e. bool fields)</span>
<span class='doccomment'>//! - Both short and long versions supported (i.e. `-f` and `--flag` respectively)</span>
<span class='doccomment'>//! - Supports combining short versions (i.e. `-fBgoZ` is the same as `-f -B -g -o -Z`)</span>
<span class='doccomment'>//! - Also supports multiple occurrences (i.e. `myprog -vvv` or `myprog -v -v -v`)</span>
<span class='doccomment'>//! * **Positional Arguments** (i.e. those which are based off an index)</span>
<span class='doccomment'>//! - Also supports multiple values (i.e. `myprog &lt;file&gt;...`</span>
<span class='doccomment'>//! - Supports Specific Value Sets (See below)</span>
<span class='doccomment'>//! * **Option Arguments** (i.e. those that take values as options)</span>
<span class='doccomment'>//! - Both short and long versions supported (i.e. `-o value` and `--option value` or `--option=value` respectively)</span>
<span class='doccomment'>//! - Also supports multiple values (i.e. `myprog --option &lt;value&gt; --option &lt;othervalue&gt;`)</span>
<span class='doccomment'>//! - Supports Specific Value Sets (See below)</span>
<span class='doccomment'>//! * **Sub-Commands** (i.e. `git add &lt;file&gt;` where `add` is a sub-command of `git`)</span>
<span class='doccomment'>//! - Support their own sub-arguments, and sub-commands</span>
<span class='doccomment'>//! - Get their own auto-generated Help, Version, and Usage independant of parent</span>
<span class='doccomment'>//! * **Requirement Rules**: Arguments can optionally define the following types of requirement rules</span>
<span class='doccomment'>//! - Required by default</span>
<span class='doccomment'>//! - Required only if certain arguments are present</span>
<span class='doccomment'>//! - Can require other arguments to be present</span>
<span class='doccomment'>//! * **Exclusion Rules**: Arguments can optionally define the following types of exclusion rules</span>
<span class='doccomment'>//! - Can be disallowed when certain arguments are present</span>
<span class='doccomment'>//! - Can disallow use of other arguments when present</span>
<span class='doccomment'>//! * **Specific Value Sets**: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a `--mode` option which may *only* have one of two values `fast` or `slow` such as `--mode fast` or `--mode slow`)</span>
<span class='doccomment'>//! * **Default Values**: Although not specifically provided by `clap` you can achieve this exact functionality from Rust&#39;s `Option&lt;&amp;str&gt;.unwrap_or(&quot;some default&quot;)` method</span>
<span class='doccomment'>//! * **Auto Version from Cargo.toml**: `clap` is fully compatible with Rust&#39;s `env!()` macro for achieving this functionality. See `examples/09_AutoVersion.rs` for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## Quick Example</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! The following shows a quick example of some of the basic functionality of `clap`. For more advanced usage, such as requirements, exclusions, multiple values and occurrences see the [documentation](http://kbknapp.github.io/clap-rs/docs/clap/index.html) or `examples/` directory of this repository.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ```rust</span>
<span class='doccomment'>//! // (Full example with comments in examples/01_QuickExample.rs)</span>
<span class='doccomment'>//! extern crate clap;</span>
@ -420,6 +508,7 @@
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## Installation</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Add `clap` as a dependecy in your `Cargo.toml` file to use from crates.io:</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ```</span>
@ -433,46 +522,67 @@
<span class='doccomment'>//! git = &quot;https://github.com/kbknapp/clap-rs.git&quot;</span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Then run `cargo build` or `cargo update` for your project.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## Usage</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Add `extern crate clap;` to your crate root.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Define a list of valid arguments for your program (see the documentation or examples/ directory)</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Then run `cargo build` or `cargo update &amp;&amp; cargo build` for your project.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## More Information</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! You can find complete documentation on the [github-pages site](http://kbknapp.github.io/clap-rs/docs/clap/index.html) for this project.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! You can also find full usage examples in the examples/ directory of this repo.</span>
<span class='doccomment'>//! You can also find full usage examples in the `examples/` directory of this repo.</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ## How to build</span>
<span class='doccomment'>//! ## How to build and contribute</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Clone the repo (`master` branch if using `clap`, `dev` branch if contributing) and build with Cargo</span>
<span class='doccomment'>//! Contributions are always welcome! And there is a multitude of ways in which you can help depending on what you like to do, or are good at. Anything from documentation, code cleanup, issue completion, new features, you name it, even filing issues is contributing and greatly appreciated!</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! git clone https://github.com/kbknapp/clap-rs</span>
<span class='doccomment'>//! cd clap-rs</span>
<span class='doccomment'>//! cargo build --release</span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! 1. Fork the project</span>
<span class='doccomment'>//! 2. Clone your fork (`git clone https://github.com/$USER/clap-rs &amp;&amp; cd clap-rs`)</span>
<span class='doccomment'>//! 3. Create new branch (`git checkout -b your-branch`)</span>
<span class='doccomment'>//! 4. Make your changes, and commit (`git commit -am &quot;your message&quot;`)</span>
<span class='doccomment'>//! 5. If applicable, run the tests (See below)</span>
<span class='doccomment'>//! 6. Push your changes back to your fork (`git push origin your-branch`)</span>
<span class='doccomment'>//! 7. Create a pull request! (You can create the pull request right away, and we&#39;ll merge when read. This a good way to discuss proposed changes)</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Another really great way to help is if you find an interesting, or helpful way in which to use `clap` you can either add it to the `examples/` directory, or file an issue and tell me. I&#39;m all about giving credit where credit is due :)</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ### Running the tests</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! If contributing, you can run the tests as follows (assuming you&#39;ve already cloned the repo to `clap-rs/`</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! cd clap-rs/claptests</span>
<span class='doccomment'>//! cd clap-rs</span>
<span class='doccomment'>//! cargo test</span>
<span class='doccomment'>//! cd claptests</span>
<span class='doccomment'>//! make test</span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ### Building the documentation</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Run this instead of `cargo doc` to generate the proper module docstring:</span>
<span class='doccomment'>//! If the changes require re-building the documentation, run this instead of `cargo doc` to generate the proper module docstring:</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! make doc</span>
<span class='doccomment'>//! ```</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! Then browse to `clap-rs/docs/index.html` in your web-browser of choice</span>
<span class='doccomment'>//! Then browse to `clap-rs/docs/clap/index.html` in your web-browser of choice to check it out. You can then create a PR on the `gh-pages` branch</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! ### Goals</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! There are a few goals of `clap` that I&#39;d like to maintain. If your proposed changes break, or go against any of these goals we&#39;ll discuss the changes further before merging (but will *not* be ignored, all contributes are welcome!). These are by no means hard-and-fast rules, as I&#39;m no expert and break them myself from time to time (even if just by mistake or ignorance :P).</span>
<span class='doccomment'>//! </span>
<span class='doccomment'>//! * Remain backwards compatible when possible</span>
<span class='doccomment'>//! - If backwards compatibility *must* be broken, use deprecation warnings if at all possible before removing legacy code</span>
<span class='doccomment'>//! - This does not apply for security concerns</span>
<span class='doccomment'>//! * Parse arguments quickly</span>
<span class='doccomment'>//! - Parsing of arguments shouldn&#39;t slow down usage of the main program</span>
<span class='doccomment'>//! - This is also true of generating help and usage information</span>
<span class='doccomment'>//! * Try not to be cognizant of memory usage</span>
<span class='doccomment'>//! - Once parsing is complete, the memory footprint of `clap` should be low since the main program is the star of the show</span>
<span class='doccomment'>//! * `panic!` on *developer* error, exit gracefully on *end-user* error</span>
<span class='doccomment'>//! </span>
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;