mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
Moved to consuming builder pattern. Cleaned up borrows and fields.
This commit is contained in:
parent
d084a40f4a
commit
ea3de882ea
10 changed files with 152 additions and 104 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1,4 +1,4 @@
|
|||
[root]
|
||||
name = "clap"
|
||||
version = "0.3.6"
|
||||
version = "0.3.7"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "clap"
|
||||
version = "0.3.6"
|
||||
version = "0.3.7"
|
||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
exclude = ["docs/*"]
|
||||
description = "A Command Line Argument Parser written in Rust"
|
||||
|
|
|
@ -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> <a id="expand-all" href="#">[+]</a>
|
||||
</span><a id='src-0' href='../src/clap/lib.rs.html#1-116'>[src]</a></span></h1>
|
||||
</span><a id='src-0' href='../src/clap/lib.rs.html#1-136'>[src]</a></span></h1>
|
||||
<div class='docblock'><p>A simply library for parsing command line arguments when writing
|
||||
command line and console applications.</p>
|
||||
|
||||
|
|
|
@ -83,28 +83,28 @@ to the user when they print version or help and usage information.</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='kw'>let</span> <span class='ident'>prog</span> <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"myprog"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.author' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.author' class='fnname'>author</a>(&mut self, a: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
</div><h4 id='method.author' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.author' class='fnname'>author</a>(self, a: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
<div class='docblock'><p>Sets a string of author(s)</p>
|
||||
|
||||
<p>Example:</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>author</span>(<span class='string'>"Kevin <kbknapp@gmail.com>"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.about' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.about' class='fnname'>about</a>(&mut self, a: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
</div><h4 id='method.about' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.about' class='fnname'>about</a>(self, a: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
<div class='docblock'><p>Sets a string briefly describing what the program does</p>
|
||||
|
||||
<p>Example:</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>about</span>(<span class='string'>"Does really amazing things to great people"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.version' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.version' class='fnname'>version</a>(&mut self, v: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
</div><h4 id='method.version' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.version' class='fnname'>version</a>(self, v: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
<div class='docblock'><p>Sets a string of the version number</p>
|
||||
|
||||
<p>Example:</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>version</span>(<span class='string'>"v0.1.24"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.arg' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.arg' class='fnname'>arg</a>(&mut self, a: &<a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a>) -> &mut <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
</div><h4 id='method.arg' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.arg' class='fnname'>arg</a>(self, a: <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
<div class='docblock'><p>Adds an argument to the list of valid possibilties</p>
|
||||
|
||||
<p>Example:</p>
|
||||
|
@ -114,7 +114,7 @@ to the user when they print version or help and usage information.</p>
|
|||
<span class='comment'>// Additional argument configuration goes here...</span>
|
||||
)
|
||||
</pre>
|
||||
</div><h4 id='method.args' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.args' class='fnname'>args</a>(&mut self, args: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&<a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a>>) -> &mut <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
</div><h4 id='method.args' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.args' class='fnname'>args</a>(self, args: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><<a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a>>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a></code></h4>
|
||||
<div class='docblock'><p>Adds arguments to the list of valid possibilties</p>
|
||||
|
||||
<p>Example:</p>
|
||||
|
@ -122,7 +122,7 @@ to the user when they print version or help and usage information.</p>
|
|||
.<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'>"config"</span>).<span class='ident'>short</span>(<span class='string'>"c"</span>),
|
||||
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"debug"</span>).<span class='ident'>short</span>(<span class='string'>"d"</span>)])
|
||||
</pre>
|
||||
</div><h4 id='method.get_matches' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.get_matches' class='fnname'>get_matches</a>(&mut self) -> <a class='struct' href='../clap/struct.ArgMatches.html' title='clap::ArgMatches'>ArgMatches</a></code></h4>
|
||||
</div><h4 id='method.get_matches' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.get_matches' class='fnname'>get_matches</a>(self) -> <a class='struct' href='../clap/struct.ArgMatches.html' title='clap::ArgMatches'>ArgMatches</a></code></h4>
|
||||
</div></section>
|
||||
<section id='search' class="content hidden"></section>
|
||||
|
||||
|
|
|
@ -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> <a id="expand-all" href="#">[+]</a>
|
||||
</span><a id='src-4414' href='../src/clap/arg.rs.html#21-53'>[src]</a></span></h1>
|
||||
</span><a id='src-4358' href='../src/clap/arg.rs.html#21-53'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct Arg {
|
||||
pub name: &'static <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><<a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a>>,
|
||||
|
@ -105,7 +105,7 @@ be displayed when the user prints the usage/help information of the program.</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"conifg"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.short' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.short' class='fnname'>short</a>(&mut self, s: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.short' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.short' class='fnname'>short</a>(self, s: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets the short version of the argument without the preceding <code>-</code>.</p>
|
||||
|
||||
<p>By default <code>clap</code> automatically assigns <code>v</code> and <code>h</code> to display version and help information
|
||||
|
@ -119,7 +119,7 @@ Example:</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>short</span>(<span class='string'>"c"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.long' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.long' class='fnname'>long</a>(&mut self, l: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.long' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.long' class='fnname'>long</a>(self, l: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets the long version of the argument without the preceding <code>--</code>.</p>
|
||||
|
||||
<p>By default <code>clap</code> automatically assigns <code>version</code> and <code>help</code> to display version and help information
|
||||
|
@ -134,7 +134,7 @@ when the user mistakenly sets the short to <code>--out</code> or the like.</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>long</span>(<span class='string'>"config"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.help' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.help' class='fnname'>help</a>(&mut self, h: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.help' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.help' class='fnname'>help</a>(self, h: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets the help text of the argument that will be displayed to the user
|
||||
when they print the usage/help information. </p>
|
||||
|
||||
|
@ -142,7 +142,7 @@ when they print the usage/help information. </p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>help</span>(<span class='string'>"The config file used by the myprog"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.required' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.required' class='fnname'>required</a>(&mut self, r: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.required' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.required' class='fnname'>required</a>(self, r: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets whether or not the argument is required by default. Required by
|
||||
default means it is required, when no other mutually exlusive rules have
|
||||
been evaluated. Mutually exclusive rules take precedence over being required
|
||||
|
@ -156,7 +156,7 @@ when they print the usage/help information. </p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>required</span>(<span class='boolval'>true</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.mutually_excludes' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes' class='fnname'>mutually_excludes</a>(&mut self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.mutually_excludes' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes' class='fnname'>mutually_excludes</a>(self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets a mutually exclusive argument by name. I.e. when using this argument,
|
||||
the following argument can't be present.</p>
|
||||
|
||||
|
@ -168,7 +168,7 @@ arguments, they do not need to be set for each.</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>mutually_excludes</span>(<span class='string'>"debug"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.mutually_excludes_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes_all' class='fnname'>mutually_excludes_all</a>(&mut self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.mutually_excludes_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes_all' class='fnname'>mutually_excludes_all</a>(self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets a mutually exclusive arguments by names. I.e. when using this argument,
|
||||
the following argument can't be present.</p>
|
||||
|
||||
|
@ -181,7 +181,7 @@ arguments, they do not need to be set for each.</p>
|
|||
.<span class='ident'>mutually_excludes_all</span>(
|
||||
<span class='macro'>vec</span><span class='macro'>!</span>[<span class='string'>"debug"</span>, <span class='string'>"input"</span>])
|
||||
</pre>
|
||||
</div><h4 id='method.requires' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires' class='fnname'>requires</a>(&mut self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.requires' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires' class='fnname'>requires</a>(self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets an argument by name that is required when this one is presnet I.e. when
|
||||
using this argument, the following argument <em>must</em> be present.</p>
|
||||
|
||||
|
@ -191,7 +191,7 @@ using this argument, the following argument <em>must</em> be present.</p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>requires</span>(<span class='string'>"debug"</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.requires_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires_all' class='fnname'>requires_all</a>(&mut self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.requires_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires_all' class='fnname'>requires_all</a>(self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Sets arguments by names that are required when this one is presnet I.e. when
|
||||
using this argument, the following arguments <em>must</em> be present.</p>
|
||||
|
||||
|
@ -203,7 +203,7 @@ using this argument, the following argument <em>must</em> be present.</p>
|
|||
.<span class='ident'>requires_all</span>(
|
||||
<span class='macro'>vec</span><span class='macro'>!</span>[<span class='string'>"debug"</span>, <span class='string'>"input"</span>])
|
||||
</pre>
|
||||
</div><h4 id='method.takes_value' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.takes_value' class='fnname'>takes_value</a>(&mut self, tv: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.takes_value' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.takes_value' class='fnname'>takes_value</a>(self, tv: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Specifies that the argument takes an additional value at run time.</p>
|
||||
|
||||
<p><strong>NOTE:</strong> When setting this to <code>true</code> the <code>name</code> of the argument
|
||||
|
@ -213,7 +213,7 @@ will be used when printing the help/usage information to the user. </p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.index' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.index' class='fnname'>index</a>(&mut self, idx: <a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.index' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.index' class='fnname'>index</a>(self, idx: <a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Specifies the index of a positional argument starting at 1.</p>
|
||||
|
||||
<p><strong>NOTE:</strong> When setting this, any <code>short</code> or <code>long</code> values you set
|
||||
|
@ -225,7 +225,7 @@ to the user. </p>
|
|||
<pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>index</span>(<span class='number'>1</span>)
|
||||
</pre>
|
||||
</div><h4 id='method.multiple' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.multiple' class='fnname'>multiple</a>(&mut self, multi: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> &mut <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
</div><h4 id='method.multiple' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.multiple' class='fnname'>multiple</a>(self, multi: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
||||
<div class='docblock'><p>Specifies if the flag may appear more than once such as for multiple debugging
|
||||
levels (as an example). <code>-ddd</code> for three levels of debugging, or <code>-d -d -d</code>.
|
||||
When this is set to <code>true</code> you recieve the number of occurances the user supplied
|
||||
|
|
|
@ -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> <a id="expand-all" href="#">[+]</a>
|
||||
</span><a id='src-4244' href='../src/clap/argmatches.rs.html#49-59'>[src]</a></span></h1>
|
||||
</span><a id='src-4188' href='../src/clap/argmatches.rs.html#49-59'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct ArgMatches {
|
||||
pub name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>,
|
||||
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><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>, FlagArg>,
|
||||
|
|
|
@ -757,6 +757,10 @@
|
|||
<span id="715">715</span>
|
||||
<span id="716">716</span>
|
||||
<span id="717">717</span>
|
||||
<span id="718">718</span>
|
||||
<span id="719">719</span>
|
||||
<span id="720">720</span>
|
||||
<span id="721">721</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
|
||||
|
||||
|
@ -806,7 +810,7 @@
|
|||
<span class='ident'>flags</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>, <span class='ident'>FlagArg</span><span class='op'>></span>,
|
||||
<span class='ident'>opts</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>, <span class='ident'>OptArg</span><span class='op'>></span>,
|
||||
<span class='ident'>positionals_idx</span>: <span class='ident'>BTreeMap</span><span class='op'><</span><span class='ident'>u8</span>, <span class='ident'>PosArg</span><span class='op'>></span>,
|
||||
<span class='ident'>positionals_name</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>, <span class='ident'>PosArg</span><span class='op'>></span>,
|
||||
<span class='comment'>// positionals_name: HashMap<&'static str, PosArg>,</span>
|
||||
<span class='ident'>needs_long_help</span>: <span class='ident'>bool</span>,
|
||||
<span class='ident'>needs_long_version</span>: <span class='ident'>bool</span>,
|
||||
<span class='ident'>needs_short_help</span>: <span class='ident'>bool</span>,
|
||||
|
@ -838,7 +842,7 @@
|
|||
<span class='ident'>flags</span>: <span class='ident'>HashMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>opts</span>: <span class='ident'>HashMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>positionals_idx</span>: <span class='ident'>BTreeMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>positionals_name</span>: <span class='ident'>HashMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='comment'>// positionals_name: HashMap::new(),</span>
|
||||
<span class='ident'>needs_long_version</span>: <span class='boolval'>true</span>,
|
||||
<span class='ident'>needs_long_help</span>: <span class='boolval'>true</span>,
|
||||
<span class='ident'>needs_short_help</span>: <span class='boolval'>true</span>,
|
||||
|
@ -861,7 +865,7 @@
|
|||
<span class='doccomment'>/// .author("Kevin <kbknapp@gmail.com>")</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>author</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>author</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>App</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>author</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>);
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -876,7 +880,7 @@
|
|||
<span class='doccomment'>/// .about("Does really amazing things to great people")</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>about</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>about</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>App</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>about</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>);
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -891,7 +895,7 @@
|
|||
<span class='doccomment'>/// .version("v0.1.24")</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>version</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>v</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>)<span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>version</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>v</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>)<span class='op'>-></span> <span class='ident'>App</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>version</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>);
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -909,7 +913,7 @@
|
|||
<span class='doccomment'>/// )</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>arg</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='ident'>Arg</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>arg</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='ident'>Arg</span>) <span class='op'>-></span> <span class='ident'>App</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>arg_list</span>.<span class='ident'>contains</span>(<span class='ident'>a</span>.<span class='ident'>name</span>) {
|
||||
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument name must be unique, \"{}\" is already in use"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
|
@ -933,21 +937,21 @@
|
|||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</span>);
|
||||
}
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>i</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>index</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>positionals_name</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</span>, <span class='ident'>PosArg</span> {
|
||||
<span class='ident'>name</span>: <span class='ident'>a</span>.<span class='ident'>name</span>,
|
||||
<span class='ident'>index</span>: <span class='ident'>i</span>,
|
||||
<span class='ident'>required</span>: <span class='ident'>a</span>.<span class='ident'>required</span>,
|
||||
<span class='ident'>help</span>: <span class='ident'>a</span>.<span class='ident'>help</span>,
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>value</span>: <span class='prelude-val'>None</span>
|
||||
});
|
||||
<span class='comment'>// self.positionals_name.insert(a.name, PosArg {</span>
|
||||
<span class='comment'>// name: a.name,</span>
|
||||
<span class='comment'>// index: i,</span>
|
||||
<span class='comment'>// required: a.required,</span>
|
||||
<span class='comment'>// help: a.help,</span>
|
||||
<span class='comment'>// blacklist: a.blacklist,</span>
|
||||
<span class='comment'>// requires: a.requires,</span>
|
||||
<span class='comment'>// value: None</span>
|
||||
<span class='comment'>// });</span>
|
||||
<span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>insert</span>(<span class='ident'>i</span>, <span class='ident'>PosArg</span> {
|
||||
<span class='ident'>name</span>: <span class='ident'>a</span>.<span class='ident'>name</span>,
|
||||
<span class='ident'>index</span>: <span class='ident'>i</span>,
|
||||
<span class='ident'>required</span>: <span class='ident'>a</span>.<span class='ident'>required</span>,
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>,
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>,
|
||||
<span class='ident'>help</span>: <span class='ident'>a</span>.<span class='ident'>help</span>,
|
||||
<span class='ident'>value</span>: <span class='prelude-val'>None</span>
|
||||
});
|
||||
|
@ -959,9 +963,9 @@
|
|||
<span class='ident'>name</span>: <span class='ident'>a</span>.<span class='ident'>name</span>,
|
||||
<span class='ident'>short</span>: <span class='ident'>a</span>.<span class='ident'>short</span>,
|
||||
<span class='ident'>long</span>: <span class='ident'>a</span>.<span class='ident'>long</span>,
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>,
|
||||
<span class='ident'>help</span>: <span class='ident'>a</span>.<span class='ident'>help</span>,
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>,
|
||||
<span class='ident'>required</span>: <span class='ident'>a</span>.<span class='ident'>required</span>,
|
||||
<span class='ident'>value</span>: <span class='prelude-val'>None</span>
|
||||
});
|
||||
|
@ -992,9 +996,9 @@
|
|||
<span class='ident'>short</span>: <span class='ident'>a</span>.<span class='ident'>short</span>,
|
||||
<span class='ident'>long</span>: <span class='ident'>a</span>.<span class='ident'>long</span>,
|
||||
<span class='ident'>help</span>: <span class='ident'>a</span>.<span class='ident'>help</span>,
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>a</span>.<span class='ident'>blacklist</span>,
|
||||
<span class='ident'>multiple</span>: <span class='ident'>a</span>.<span class='ident'>multiple</span>,
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>.<span class='ident'>clone</span>(),
|
||||
<span class='ident'>requires</span>: <span class='ident'>a</span>.<span class='ident'>requires</span>,
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>
|
||||
});
|
||||
}
|
||||
|
@ -1012,9 +1016,9 @@
|
|||
<span class='doccomment'>/// Arg::new("debug").short("d")])</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>args</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>args</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>Arg</span><span class='op'>></span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>arg</span> <span class='kw'>in</span> <span class='ident'>args</span>.<span class='ident'>iter</span>() {
|
||||
<span class='self'>self</span>.<span class='ident'>arg</span>(<span class='ident'>arg</span>);
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>args</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>args</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='ident'>Arg</span><span class='op'>></span>) <span class='op'>-></span> <span class='ident'>App</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>arg</span> <span class='kw'>in</span> <span class='ident'>args</span>.<span class='ident'>into_iter</span>() {
|
||||
<span class='self'>self</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>arg</span>(<span class='ident'>arg</span>);
|
||||
}
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -1023,10 +1027,10 @@
|
|||
<span class='kw'>unsafe</span> { <span class='ident'>libc</span>::<span class='ident'>exit</span>(<span class='number'>0</span>); }
|
||||
}
|
||||
|
||||
<span class='kw'>fn</span> <span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>msg</span>: <span class='kw-2'>&</span><span class='ident'>String</span>, <span class='ident'>help</span>: <span class='ident'>bool</span>, <span class='ident'>quit</span>: <span class='ident'>bool</span>) {
|
||||
<span class='kw'>fn</span> <span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>msg</span>: <span class='ident'>String</span>, <span class='ident'>help</span>: <span class='ident'>bool</span>, <span class='ident'>quit</span>: <span class='ident'>bool</span>) {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}"</span>, <span class='ident'>msg</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>help</span> { <span class='self'>self</span>.<span class='ident'>print_help</span>(); }
|
||||
<span class='kw'>if</span> <span class='ident'>quit</span> {<span class='self'>self</span>.<span class='ident'>exit</span>(); }
|
||||
<span class='kw'>if</span> <span class='ident'>quit</span> { <span class='ident'>env</span>::<span class='ident'>set_exit_status</span>(<span class='number'>1</span>); <span class='self'>self</span>.<span class='ident'>exit</span>(); }
|
||||
}
|
||||
|
||||
<span class='kw'>fn</span> <span class='ident'>print_help</span>(<span class='kw-2'>&</span><span class='self'>self</span>) {
|
||||
|
@ -1035,10 +1039,10 @@
|
|||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>pos</span> <span class='op'>=</span> <span class='boolval'>false</span>;
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>opts</span> <span class='op'>=</span> <span class='boolval'>false</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'>author</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>author</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'>"{}"</span>, <span class='ident'>author</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'>about</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>about</span> {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>about</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>about</span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}"</span>, <span class='ident'>about</span>);
|
||||
}
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
|
@ -1046,24 +1050,24 @@
|
|||
<span class='macro'>print</span><span class='macro'>!</span>(<span class='string'>"\t{} {} {} {}"</span>, <span class='self'>self</span>.<span class='ident'>name</span>,
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>is_empty</span>() {<span class='ident'>flags</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>"[FLAGS]"</span>} <span class='kw'>else</span> {<span class='string'>""</span>},
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>is_empty</span>() {<span class='ident'>opts</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>"[OPTIONS]"</span>} <span class='kw'>else</span> {<span class='string'>""</span>},
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='self'>self</span>.<span class='ident'>positionals_name</span>.<span class='ident'>is_empty</span>() {<span class='ident'>pos</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>"[POSITIONAL]"</span>} <span class='kw'>else</span> {<span class='string'>""</span>});
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>is_empty</span>() {<span class='ident'>pos</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>"[POSITIONAL]"</span>} <span class='kw'>else</span> {<span class='string'>""</span>});
|
||||
<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='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>flags</span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"FLAGS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>iter</span>() {
|
||||
<span class='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'>"\t{}{}\t{}"</span>,
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" \t"</span>)},
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
<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'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" \t"</span>)},
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
}
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>opts</span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"OPTIONS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>iter</span>() {
|
||||
<span class='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='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}{}\t\t{}"</span>,
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
||||
|
@ -1074,9 +1078,9 @@
|
|||
<span class='kw'>if</span> <span class='ident'>pos</span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"POSITIONAL ARGUMENTS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>iter</span>() {
|
||||
<span class='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'>"\t{}\t\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>,
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
<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='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1088,7 @@
|
|||
}
|
||||
|
||||
<span class='kw'>fn</span> <span class='ident'>print_version</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>quit</span>: <span class='ident'>bool</span>) {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} {}"</span>, <span class='self'>self</span>.<span class='ident'>name</span>, <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>version</span> {<span class='op'>*</span><span class='ident'>v</span>} <span class='kw'>else</span> {<span class='string'>""</span>} );
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} {}"</span>, <span class='self'>self</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'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>version</span> {<span class='ident'>v</span>} <span class='kw'>else</span> {<span class='string'>""</span>} );
|
||||
<span class='kw'>if</span> <span class='ident'>quit</span> { <span class='self'>self</span>.<span class='ident'>exit</span>(); }
|
||||
}
|
||||
|
||||
|
@ -1118,7 +1122,7 @@
|
|||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {
|
||||
<span class='kw'>if</span> <span class='op'>*</span><span class='ident'>l</span> <span class='op'>==</span> <span class='ident'>arg</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>k</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} is mutually exclusive with one or more other arguments"</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'>"The argument --{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>k</span>, <span class='ident'>OptArg</span>{
|
||||
|
@ -1150,7 +1154,7 @@
|
|||
}
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='ident'>multi</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>k</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} is mutually exclusive with one or more other arguments"</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'>"The argument --{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>insert</span>(<span class='ident'>k</span>, <span class='ident'>FlagArg</span>{
|
||||
|
@ -1190,7 +1194,7 @@
|
|||
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='ident'>found</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument --{} isn't valid"</span>, <span class='ident'>arg</span>),
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument --{} isn't valid"</span>, <span class='ident'>arg</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='prelude-val'>None</span>
|
||||
|
@ -1204,7 +1208,7 @@
|
|||
<span class='self'>self</span>.<span class='ident'>check_for_help_and_version</span>(<span class='ident'>c</span>);
|
||||
<span class='kw'>if</span> <span class='op'>!</span> <span class='self'>self</span>.<span class='ident'>parse_single_short_flag</span>(<span class='ident'>matches</span>, <span class='ident'>c</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} isn't valid"</span>,<span class='ident'>c</span>),
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} isn't valid"</span>,<span class='ident'>c</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
}
|
||||
|
@ -1223,7 +1227,7 @@
|
|||
}
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} isn't valid"</span>,<span class='ident'>arg_c</span>),
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} isn't valid"</span>,<span class='ident'>arg_c</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
|
@ -1238,7 +1242,7 @@
|
|||
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>k</span>) {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>k</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument -{} is mutually exclusive with one or more other arguments"</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'>"The argument -{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>insert</span>(<span class='ident'>k</span>, <span class='ident'>FlagArg</span>{
|
||||
|
@ -1286,7 +1290,7 @@
|
|||
<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'>for</span> (<span class='ident'>k</span>, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>iter</span>() {
|
||||
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>==</span> <span class='ident'>name</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</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'>"-{}"</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='ident'>v</span>.<span class='ident'>long</span> {
|
||||
|
@ -1299,7 +1303,7 @@
|
|||
}
|
||||
<span class='kw'>for</span> (<span class='ident'>k</span>, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>iter</span>() {
|
||||
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>==</span> <span class='ident'>name</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</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'>"-{}"</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='ident'>v</span>.<span class='ident'>long</span> {
|
||||
|
@ -1312,7 +1316,7 @@
|
|||
}
|
||||
<span class='kw'>for</span> (<span class='ident'>k</span>, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>iter</span>() {
|
||||
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>==</span> <span class='ident'>name</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</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'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</span>,<span class='ident'>v</span>.<span class='ident'>name</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
}
|
||||
|
@ -1320,9 +1324,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_matches</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-></span> <span class='ident'>ArgMatches</span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>ArgMatches</span>::<span class='ident'>new</span>(<span class='self'>self</span>);
|
||||
|
||||
<span class='kw'>fn</span> <span class='ident'>create_help_and_version</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>needs_long_help</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>insert</span>(<span class='string'>"clap_help"</span>, <span class='ident'>FlagArg</span>{
|
||||
<span class='ident'>name</span>: <span class='string'>"clap_help"</span>,
|
||||
|
@ -1347,18 +1349,24 @@
|
|||
<span class='ident'>occurrences</span>: <span class='number'>1</span>
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
<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'>-></span> <span class='ident'>ArgMatches</span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>ArgMatches</span>::<span class='ident'>new</span>(<span class='kw-2'>&</span><span class='self'>self</span>);
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>create_help_and_version</span>();
|
||||
|
||||
<span class='comment'>// let mut needs_val = false;</span>
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>needs_val_of</span>: <span class='prelude-ty'>Option</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>pos_counter</span> <span class='op'>=</span> <span class='number'>1</span>;
|
||||
<span class='kw'>for</span> <span class='ident'>arg</span> <span class='kw'>in</span> <span class='ident'>env</span>::<span class='ident'>args</span>().<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span><span class='ident'>String</span><span class='op'>>></span>().<span class='ident'>tail</span>() {
|
||||
<span class='kw'>for</span> <span class='ident'>arg</span> <span class='kw'>in</span> <span class='ident'>env</span>::<span class='ident'>args</span>().<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span>_<span class='op'>>></span>().<span class='ident'>tail</span>() {
|
||||
<span class='kw'>let</span> <span class='ident'>arg_slice</span> <span class='op'>=</span> <span class='ident'>arg</span>.<span class='ident'>as_slice</span>();
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>skip</span> <span class='op'>=</span> <span class='boolval'>false</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'>nvo</span>) <span class='op'>=</span> <span class='ident'>needs_val_of</span> {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>nvo</span>) <span class='op'>=</span> <span class='ident'>needs_val_of</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'>opt</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>nvo</span>) {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>opt</span>.<span class='ident'>name</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>long</span>) <span class='op'>=</span> <span class='ident'>opt</span>.<span class='ident'>long</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"--{}"</span>,<span class='ident'>long</span>)
|
||||
}<span class='kw'>else</span>{
|
||||
|
@ -1411,14 +1419,14 @@
|
|||
} <span class='kw'>else</span> {
|
||||
<span class='comment'>// Positional</span>
|
||||
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>is_empty</span>() <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>positionals_name</span>.<span class='ident'>is_empty</span>() {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>is_empty</span>() { <span class='comment'>// || self.positionals_name.is_empty() {</span>
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Found positional argument {}, but {} doesn't accept any"</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>),
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Found positional argument {}, but {} doesn't accept any"</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>),
|
||||
<span class='boolval'>false</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='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'>&</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='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</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'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>, <span class='ident'>PosArg</span>{
|
||||
|
@ -1452,7 +1460,7 @@
|
|||
}
|
||||
<span class='ident'>pos_counter</span> <span class='op'>+=</span> <span class='number'>1</span>;
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Positional argument \"{}\" was found, but {} wasn't expecting any"</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>), <span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Positional argument \"{}\" was found, but {} wasn't expecting any"</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>), <span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1460,13 +1468,13 @@
|
|||
<span class='kw'>match</span> <span class='ident'>needs_val_of</span> {
|
||||
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>a</span>) <span class='op'>=></span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(
|
||||
<span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" requires a value but none was supplied"</span>, <span class='ident'>a</span>),
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" requires a value but none was supplied"</span>, <span class='ident'>a</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
_ <span class='op'>=></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='kw-2'>&</span><span class='string'>"One or more required arguments were not supplied"</span>.<span class='ident'>to_string</span>(),
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='string'>"One or more required arguments were not supplied"</span>.<span class='ident'>to_string</span>(),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .short("c")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>short</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>s</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>short</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>s</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>short</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>.<span class='ident'>trim_left_matches</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'-'</span>)
|
||||
.<span class='ident'>char_at</span>(<span class='number'>0</span>));
|
||||
<span class='self'>self</span>
|
||||
|
@ -510,7 +510,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .long("config")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>long</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>l</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>long</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>l</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>long</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>.<span class='ident'>trim_left_matches</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'-'</span>));
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -527,7 +527,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .help("The config file used by the myprog")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>help</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>h</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>help</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>h</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>help</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>);
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -550,7 +550,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .required(true)</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>required</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>r</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>required</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>r</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>required</span> <span class='op'>=</span> <span class='ident'>r</span>;
|
||||
<span class='self'>self</span>
|
||||
}
|
||||
|
@ -569,7 +569,7 @@
|
|||
<span class='doccomment'>/// # let myprog = App::new("myprog").arg(Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .mutually_excludes("debug")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mutually_excludes</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mutually_excludes</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</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'>vec</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>blacklist</span> {
|
||||
<span class='ident'>vec</span>.<span class='ident'>push</span>(<span class='ident'>name</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
|
@ -593,7 +593,7 @@
|
|||
<span class='doccomment'>/// .mutually_excludes_all(</span>
|
||||
<span class='doccomment'>/// vec!["debug", "input"])</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mutually_excludes_all</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>names</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mutually_excludes_all</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>names</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>) <span class='op'>-></span> <span class='ident'>Arg</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'>vec</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>blacklist</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>names</span> {
|
||||
<span class='ident'>vec</span>.<span class='ident'>push</span>(<span class='ident'>n</span>);
|
||||
|
@ -616,7 +616,7 @@
|
|||
<span class='doccomment'>/// # let myprog = App::new("myprog").arg(Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .requires("debug")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>requires</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>requires</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</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'>vec</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>requires</span> {
|
||||
<span class='ident'>vec</span>.<span class='ident'>push</span>(<span class='ident'>name</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
|
@ -639,7 +639,7 @@
|
|||
<span class='doccomment'>/// .requires_all(</span>
|
||||
<span class='doccomment'>/// vec!["debug", "input"])</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>requires_all</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>names</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>requires_all</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>names</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>) <span class='op'>-></span> <span class='ident'>Arg</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'>vec</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>requires</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>names</span> {
|
||||
<span class='ident'>vec</span>.<span class='ident'>push</span>(<span class='ident'>n</span>);
|
||||
|
@ -664,7 +664,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .takes_value(true)</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>takes_value</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>tv</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>takes_value</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>tv</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='self'>self</span>.<span class='ident'>index</span> <span class='op'>==</span> <span class='prelude-val'>None</span>);
|
||||
<span class='self'>self</span>.<span class='ident'>takes_value</span> <span class='op'>=</span> <span class='ident'>tv</span>;
|
||||
<span class='self'>self</span>
|
||||
|
@ -686,7 +686,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// .index(1)</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>index</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>idx</span>: <span class='ident'>u8</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>index</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>idx</span>: <span class='ident'>u8</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='self'>self</span>.<span class='ident'>takes_value</span> <span class='op'>==</span> <span class='boolval'>false</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>idx</span> <span class='op'><</span> <span class='number'>1</span> { <span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument index must start at 1"</span>); }
|
||||
<span class='self'>self</span>.<span class='ident'>index</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>idx</span>);
|
||||
|
@ -710,7 +710,7 @@
|
|||
<span class='doccomment'>/// # Arg::new("debug")</span>
|
||||
<span class='doccomment'>/// .multiple(true)</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>multiple</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>multi</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>Arg</span> {
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>multiple</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>multi</span>: <span class='ident'>bool</span>) <span class='op'>-></span> <span class='ident'>Arg</span> {
|
||||
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='self'>self</span>.<span class='ident'>takes_value</span> <span class='op'>==</span> <span class='boolval'>false</span>);
|
||||
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='self'>self</span>.<span class='ident'>index</span> <span class='op'>==</span> <span class='prelude-val'>None</span>);
|
||||
<span class='self'>self</span>.<span class='ident'>multiple</span> <span class='op'>=</span> <span class='ident'>multi</span>;
|
||||
|
|
|
@ -305,7 +305,7 @@
|
|||
<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'>pos</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=</span> <span class='ident'>pos</span>.<span class='ident'>value</span> {
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='prelude-val'>None</span>
|
||||
}
|
||||
|
|
|
@ -156,6 +156,26 @@
|
|||
<span id="114">114</span>
|
||||
<span id="115">115</span>
|
||||
<span id="116">116</span>
|
||||
<span id="117">117</span>
|
||||
<span id="118">118</span>
|
||||
<span id="119">119</span>
|
||||
<span id="120">120</span>
|
||||
<span id="121">121</span>
|
||||
<span id="122">122</span>
|
||||
<span id="123">123</span>
|
||||
<span id="124">124</span>
|
||||
<span id="125">125</span>
|
||||
<span id="126">126</span>
|
||||
<span id="127">127</span>
|
||||
<span id="128">128</span>
|
||||
<span id="129">129</span>
|
||||
<span id="130">130</span>
|
||||
<span id="131">131</span>
|
||||
<span id="132">132</span>
|
||||
<span id="133">133</span>
|
||||
<span id="134">134</span>
|
||||
<span id="135">135</span>
|
||||
<span id="136">136</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>
|
||||
|
||||
|
@ -250,27 +270,47 @@
|
|||
|
||||
<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='op'>*</span>;
|
||||
|
||||
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
||||
<span class='attribute'>#[<span class='ident'>should_fail</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>non_unique_arg_names</span>(){
|
||||
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test_app"</span>).<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>short</span>(<span class='string'>"s"</span>))
|
||||
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>long</span>(<span class='string'>"long"</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_fail</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>non_unique_shorts</span>(){
|
||||
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test_app"</span>).<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>short</span>(<span class='string'>"s"</span>))
|
||||
.<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"other"</span>).<span class='ident'>short</span>(<span class='string'>"s"</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_fail</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>non_unique_longs</span>(){
|
||||
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"test_app"</span>).<span class='ident'>arg</span>(<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>long</span>(<span class='string'>"long"</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'>"long"</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>)
|
||||
]);
|
||||
}
|
||||
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>create_app</span>(){
|
||||
<span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>about</span>(<span class='string'>"about"</span>).<span class='ident'>author</span>(<span class='string'>"author"</span>).<span class='ident'>version</span>(<span class='string'>"1.0"</span>);
|
||||
}
|
||||
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>create_arg_flag</span>(){
|
||||
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>short</span>(<span class='string'>"a"</span>).<span class='ident'>long</span>(<span class='string'>"long"</span>).<span class='ident'>help</span>(<span class='string'>"help with some arg"</span>).<span class='ident'>multiple</span>(<span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>create_arg_pos</span>(){
|
||||
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>index</span>(<span class='number'>1</span>).<span class='ident'>help</span>(<span class='string'>"help with some arg"</span>).<span class='ident'>required</span>(<span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='attribute'>#[<span class='ident'>test</span>]</span>
|
||||
<span class='kw'>fn</span> <span class='ident'>create_arg_opt</span>(){
|
||||
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"some"</span>).<span class='ident'>short</span>(<span class='string'>"s"</span>).<span class='ident'>long</span>(<span class='string'>"some"</span>).<span class='ident'>takes_value</span>(<span class='boolval'>true</span>).<span class='ident'>help</span>(<span class='string'>"help with some arg"</span>).<span class='ident'>required</span>(<span class='boolval'>true</span>);
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
|
Loading…
Reference in a new issue