|
|
|
@ -199,10 +199,109 @@
|
|
|
|
|
<span id="157">157</span>
|
|
|
|
|
<span id="158">158</span>
|
|
|
|
|
<span id="159">159</span>
|
|
|
|
|
<span id="160">160</span>
|
|
|
|
|
<span id="161">161</span>
|
|
|
|
|
<span id="162">162</span>
|
|
|
|
|
<span id="163">163</span>
|
|
|
|
|
<span id="164">164</span>
|
|
|
|
|
<span id="165">165</span>
|
|
|
|
|
<span id="166">166</span>
|
|
|
|
|
<span id="167">167</span>
|
|
|
|
|
<span id="168">168</span>
|
|
|
|
|
<span id="169">169</span>
|
|
|
|
|
<span id="170">170</span>
|
|
|
|
|
<span id="171">171</span>
|
|
|
|
|
<span id="172">172</span>
|
|
|
|
|
<span id="173">173</span>
|
|
|
|
|
<span id="174">174</span>
|
|
|
|
|
<span id="175">175</span>
|
|
|
|
|
<span id="176">176</span>
|
|
|
|
|
<span id="177">177</span>
|
|
|
|
|
<span id="178">178</span>
|
|
|
|
|
<span id="179">179</span>
|
|
|
|
|
<span id="180">180</span>
|
|
|
|
|
<span id="181">181</span>
|
|
|
|
|
<span id="182">182</span>
|
|
|
|
|
<span id="183">183</span>
|
|
|
|
|
<span id="184">184</span>
|
|
|
|
|
<span id="185">185</span>
|
|
|
|
|
<span id="186">186</span>
|
|
|
|
|
<span id="187">187</span>
|
|
|
|
|
<span id="188">188</span>
|
|
|
|
|
<span id="189">189</span>
|
|
|
|
|
<span id="190">190</span>
|
|
|
|
|
<span id="191">191</span>
|
|
|
|
|
<span id="192">192</span>
|
|
|
|
|
<span id="193">193</span>
|
|
|
|
|
<span id="194">194</span>
|
|
|
|
|
<span id="195">195</span>
|
|
|
|
|
<span id="196">196</span>
|
|
|
|
|
<span id="197">197</span>
|
|
|
|
|
<span id="198">198</span>
|
|
|
|
|
<span id="199">199</span>
|
|
|
|
|
<span id="200">200</span>
|
|
|
|
|
<span id="201">201</span>
|
|
|
|
|
<span id="202">202</span>
|
|
|
|
|
<span id="203">203</span>
|
|
|
|
|
<span id="204">204</span>
|
|
|
|
|
<span id="205">205</span>
|
|
|
|
|
<span id="206">206</span>
|
|
|
|
|
<span id="207">207</span>
|
|
|
|
|
<span id="208">208</span>
|
|
|
|
|
<span id="209">209</span>
|
|
|
|
|
<span id="210">210</span>
|
|
|
|
|
<span id="211">211</span>
|
|
|
|
|
<span id="212">212</span>
|
|
|
|
|
<span id="213">213</span>
|
|
|
|
|
<span id="214">214</span>
|
|
|
|
|
<span id="215">215</span>
|
|
|
|
|
<span id="216">216</span>
|
|
|
|
|
<span id="217">217</span>
|
|
|
|
|
<span id="218">218</span>
|
|
|
|
|
<span id="219">219</span>
|
|
|
|
|
<span id="220">220</span>
|
|
|
|
|
<span id="221">221</span>
|
|
|
|
|
<span id="222">222</span>
|
|
|
|
|
<span id="223">223</span>
|
|
|
|
|
<span id="224">224</span>
|
|
|
|
|
<span id="225">225</span>
|
|
|
|
|
<span id="226">226</span>
|
|
|
|
|
<span id="227">227</span>
|
|
|
|
|
<span id="228">228</span>
|
|
|
|
|
<span id="229">229</span>
|
|
|
|
|
<span id="230">230</span>
|
|
|
|
|
<span id="231">231</span>
|
|
|
|
|
<span id="232">232</span>
|
|
|
|
|
<span id="233">233</span>
|
|
|
|
|
<span id="234">234</span>
|
|
|
|
|
<span id="235">235</span>
|
|
|
|
|
<span id="236">236</span>
|
|
|
|
|
<span id="237">237</span>
|
|
|
|
|
<span id="238">238</span>
|
|
|
|
|
<span id="239">239</span>
|
|
|
|
|
<span id="240">240</span>
|
|
|
|
|
<span id="241">241</span>
|
|
|
|
|
<span id="242">242</span>
|
|
|
|
|
<span id="243">243</span>
|
|
|
|
|
<span id="244">244</span>
|
|
|
|
|
<span id="245">245</span>
|
|
|
|
|
<span id="246">246</span>
|
|
|
|
|
<span id="247">247</span>
|
|
|
|
|
<span id="248">248</span>
|
|
|
|
|
<span id="249">249</span>
|
|
|
|
|
<span id="250">250</span>
|
|
|
|
|
<span id="251">251</span>
|
|
|
|
|
<span id="252">252</span>
|
|
|
|
|
<span id="253">253</span>
|
|
|
|
|
<span id="254">254</span>
|
|
|
|
|
<span id="255">255</span>
|
|
|
|
|
<span id="256">256</span>
|
|
|
|
|
<span id="257">257</span>
|
|
|
|
|
<span id="258">258</span>
|
|
|
|
|
<span id="259">259</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'>"lib"</span>]</span>
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>libc</span>)]</span>
|
|
|
|
|
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>exit_status</span>)]</span>
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// DOCS</span>
|
|
|
|
@ -349,6 +448,8 @@
|
|
|
|
|
<span class='doccomment'>//! make doc</span>
|
|
|
|
|
<span class='doccomment'>//! ```</span>
|
|
|
|
|
|
|
|
|
|
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
|
|
|
|
|
|
|
|
|
|
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='ident'>args</span>::{<span class='ident'>Arg</span>, <span class='ident'>SubCommand</span>, <span class='ident'>ArgMatches</span>};
|
|
|
|
|
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='ident'>app</span>::<span class='ident'>App</span>;
|
|
|
|
|
|
|
|
|
@ -357,7 +458,106 @@
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>cfg</span>(<span class='ident'>test</span>)]</span>
|
|
|
|
|
<span class='kw'>mod</span> <span class='ident'>tests</span> {
|
|
|
|
|
<span class='kw'>use</span> <span class='ident'>super</span>::<span class='op'>*</span>;
|
|
|
|
|
<span class='kw'>use</span> <span class='ident'>super</span>::{<span class='ident'>App</span>, <span class='ident'>Arg</span>, <span class='ident'>SubCommand</span>};
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_app</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>).<span class='ident'>version</span>(<span class='string'>"1.0"</span>).<span class='ident'>author</span>(<span class='string'>"kevin"</span>).<span class='ident'>about</span>(<span class='string'>"does awesome things"</span>).<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>add_multiple_arg</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>args</span>( <span class='macro'>vec</span><span class='macro'>!</span>[
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>).<span class='ident'>short</span>(<span class='string'>"s"</span>),
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test2"</span>).<span class='ident'>short</span>(<span class='string'>"l"</span>)])
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_flag</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>short</span>(<span class='string'>"t"</span>)
|
|
|
|
|
.<span class='ident'>long</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>help</span>(<span class='string'>"testing testing"</span>))
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_positional</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>index</span>(<span class='number'>1</span>)
|
|
|
|
|
.<span class='ident'>help</span>(<span class='string'>"testing testing"</span>))
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_option</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>short</span>(<span class='string'>"t"</span>)
|
|
|
|
|
.<span class='ident'>long</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
|
|
|
|
.<span class='ident'>help</span>(<span class='string'>"testing testing"</span>))
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_subcommand</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>subcommand</span>(<span class='ident'>SubCommand</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>short</span>(<span class='string'>"t"</span>)
|
|
|
|
|
.<span class='ident'>long</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
|
|
|
|
.<span class='ident'>help</span>(<span class='string'>"testing testing"</span>)))
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"other"</span>).<span class='ident'>long</span>(<span class='string'>"other"</span>))
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>create_multiple_subcommands</span>() {
|
|
|
|
|
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>subcommands</span>(<span class='macro'>vec</span><span class='macro'>!</span>[ <span class='ident'>SubCommand</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>short</span>(<span class='string'>"t"</span>)
|
|
|
|
|
.<span class='ident'>long</span>(<span class='string'>"test"</span>)
|
|
|
|
|
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
|
|
|
|
.<span class='ident'>help</span>(<span class='string'>"testing testing"</span>)),
|
|
|
|
|
<span class='ident'>SubCommand</span>::<span class='ident'>new</span>(<span class='string'>"add"</span>)
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"roster"</span>).<span class='ident'>short</span>(<span class='string'>"r"</span>))])
|
|
|
|
|
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"other"</span>).<span class='ident'>long</span>(<span class='string'>"other"</span>))
|
|
|
|
|
.<span class='ident'>get_matches</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>should_panic</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>unique_arg_names</span>(){
|
|
|
|
|
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>args</span>(<span class='macro'>vec</span><span class='macro'>!</span>[
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg"</span>).<span class='ident'>short</span>(<span class='string'>"a"</span>),
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg"</span>).<span class='ident'>short</span>(<span class='string'>"b"</span>)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>should_panic</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>unique_arg_shorts</span>(){
|
|
|
|
|
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>args</span>(<span class='macro'>vec</span><span class='macro'>!</span>[
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg1"</span>).<span class='ident'>short</span>(<span class='string'>"a"</span>),
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg2"</span>).<span class='ident'>short</span>(<span class='string'>"a"</span>)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>should_panic</span>]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>unique_arg_longs</span>(){
|
|
|
|
|
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>args</span>(<span class='macro'>vec</span><span class='macro'>!</span>[
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg1"</span>).<span class='ident'>long</span>(<span class='string'>"long"</span>),
|
|
|
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"arg2"</span>).<span class='ident'>long</span>(<span class='string'>"long"</span>)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</pre>
|
|
|
|
|
</section>
|
|
|
|
|