mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
chore(docs): rebuild docs after refactor
This commit is contained in:
parent
3a1daaf957
commit
bd10dadebe
19 changed files with 211 additions and 159 deletions
0
docs/clap/args/argbuilder/index.html
Normal file
0
docs/clap/args/argbuilder/index.html
Normal file
1
docs/clap/args/argbuilder/sidebar-items.js
Normal file
1
docs/clap/args/argbuilder/sidebar-items.js
Normal file
|
@ -0,0 +1 @@
|
|||
initSidebarItems({});
|
|
@ -114,7 +114,7 @@
|
|||
<li><strong>Specific Value Sets</strong>: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a <code>--mode</code> option which may <em>only</em> have one of two values <code>fast</code> or <code>slow</code> such as <code>--mode fast</code> or <code>--mode slow</code>)</li>
|
||||
<li><strong>Default Values</strong>: Although not specifically provided by <code>clap</code> you can achieve this exact functionality from Rust's <code>Option<&str>.unwrap_or("some default")</code> method (or <code>Result<T,String>.unwrap_or(T)</code> when using typed values)</li>
|
||||
<li><strong>Automatic Version from Cargo.toml</strong>: <code>clap</code> is fully compatible with Rust's <code>env!()</code> macro for automatically setting the version of your application to the version in your Cargo.toml. See <code>examples/09_AutoVersion.rs</code> for how to do this (Thanks to <a href="https://github.com/jhelwig">jhelwig</a> for pointing this out)</li>
|
||||
<li><strong>Typed Values</strong>: You can use several convenience macros provided by <code>clap</code> to get typed values (i.e. <code>i32</code>, <code>u8</code>, etc.) from positional or option arguments so long as the type you request implements <code>std::str::FromStr</code> See the <code>examples/12_TypedValues.rs</code>. You can also use <code>clap</code>s <code>simple_enum!</code> macro to create an enum with variants that automatically implements <code>std::str::FromStr</code> in order to use with the other <code>clap</code> macros. See <code>examples/13a_EnumValuesAutomatic.rs</code> for details.</li>
|
||||
<li><strong>Typed Values</strong>: You can use several convenience macros provided by <code>clap</code> to get typed values (i.e. <code>i32</code>, <code>u8</code>, etc.) from positional or option arguments so long as the type you request implements <code>std::str::FromStr</code> See the <code>examples/12_TypedValues.rs</code>. You can also use <code>clap</code>s <code>simple_enum!</code> or <code>arg_enum!</code> macro to create an enum with variants that automatically implements <code>std::str::FromStr</code>. See <code>examples/13a_EnumValuesAutomatic.rs</code> for details.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="quick-example" class='section-header'><a
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content macro">
|
||||
<h1 class='fqn'><span class='in-band'><a href='index.html'>clap</a>::<wbr><a class='macro' href=''>arg_enum!</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-10467' href='../src/clap/macros.rs.html#297-384'>[src]</a></span></h1>
|
||||
</span><a id='src-10181' href='../src/clap/macros.rs.html#297-384'>[src]</a></span></h1>
|
||||
<pre class='rust macro'>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>arg_enum</span> {
|
||||
(<span class='kw'>enum</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>e</span>:<span class='ident'>ident</span> { $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>:<span class='ident'>ident</span>),<span class='op'>+</span> } ) <span class='op'>=></span> {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content macro">
|
||||
<h1 class='fqn'><span class='in-band'><a href='index.html'>clap</a>::<wbr><a class='macro' href=''>simple_enum!</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-10466' href='../src/clap/macros.rs.html#241-263'>[src]</a></span></h1>
|
||||
</span><a id='src-10180' href='../src/clap/macros.rs.html#241-263'>[src]</a></span></h1>
|
||||
<pre class='rust macro'>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>simple_enum</span> {
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>e</span>:<span class='ident'>ident</span> <span class='op'>=></span> $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>:<span class='ident'>ident</span>),<span class='op'>+</span>) <span class='op'>=></span> {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content macro">
|
||||
<h1 class='fqn'><span class='in-band'><a href='index.html'>clap</a>::<wbr><a class='macro' href=''>value_t!</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-10464' href='../src/clap/macros.rs.html#84-118'>[src]</a></span></h1>
|
||||
</span><a id='src-10178' href='../src/clap/macros.rs.html#84-118'>[src]</a></span></h1>
|
||||
<pre class='rust macro'>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>value_t</span> {
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>:<span class='ident'>expr</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>:<span class='ident'>ty</span>) <span class='op'>=></span> {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content macro">
|
||||
<h1 class='fqn'><span class='in-band'><a href='index.html'>clap</a>::<wbr><a class='macro' href=''>value_t_or_exit!</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-10465' href='../src/clap/macros.rs.html#166-216'>[src]</a></span></h1>
|
||||
</span><a id='src-10179' href='../src/clap/macros.rs.html#166-216'>[src]</a></span></h1>
|
||||
<pre class='rust macro'>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>value_t_or_exit</span> {
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>:<span class='ident'>expr</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>:<span class='ident'>ty</span>) <span class='op'>=></span> {
|
||||
|
|
|
@ -1 +1 @@
|
|||
initSidebarItems({"struct":[["App","Used to create a representation of a command line program and all possible command line arguments for parsing at runtime."],["Arg","The abstract representation of a command line argument used by the consumer of the library. Used to set all the options and relationships that define a valid argument for the program."],["ArgMatches","Used to get information about the arguments that where supplied to the program at runtime by the user. To get a new instance of this struct you use `.get_matches()` of the `App` struct."],["SubCommand","The abstract representation of a command line subcommand used by the consumer of the library."]],"macro":[["arg_enum!","Convenience macro to generate more complete enums with variants to be used as a type when parsing arguments."],["simple_enum!","Convenience macro generated a simple enum with variants to be used as a type when parsing arguments."],["value_t!","Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` This macro returns a `Result<T,String>` which allows you as the developer to decide what you'd like to do on a failed parse. There are two types of errors, parse failures and those where the argument wasn't present (such as a non-required argument). "],["value_t_or_exit!","Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` This macro returns a `T` or `Vec<T>` or exits with a usage string upon failure. This removes some of the boiler plate to handle failures from value_t! above. "]]});
|
||||
initSidebarItems({"macro":[["arg_enum!","Convenience macro to generate more complete enums with variants to be used as a type when parsing arguments."],["simple_enum!","Convenience macro generated a simple enum with variants to be used as a type when parsing arguments."],["value_t!","Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` This macro returns a `Result<T,String>` which allows you as the developer to decide what you'd like to do on a failed parse. There are two types of errors, parse failures and those where the argument wasn't present (such as a non-required argument). "],["value_t_or_exit!","Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` This macro returns a `T` or `Vec<T>` or exits with a usage string upon failure. This removes some of the boiler plate to handle failures from value_t! above. "]],"struct":[["App","Used to create a representation of a command line program and all possible command line arguments for parsing at runtime."],["Arg","The abstract representation of a command line argument used by the consumer of the library. Used to set all the options and relationships that define a valid argument for the program."],["ArgMatches","Used to get information about the arguments that where supplied to the program at runtime by the user. To get a new instance of this struct you use `.get_matches()` of the `App` struct."],["SubCommand","The abstract representation of a command line subcommand used by the consumer of the library."]]});
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content struct">
|
||||
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>App</a><wbr></span><span class='out-of-band'><span id='render-detail'>
|
||||
<a id="collapse-all" href="#">[-]</a> <a id="expand-all" href="#">[+]</a>
|
||||
</span><a id='src-35' href='../src/clap/app.rs.html#43-74'>[src]</a></span></h1>
|
||||
</span><a id='src-31' href='../src/clap/app.rs.html#41-72'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct App<'a, 'v, 'ab, 'u, 'ar> {
|
||||
// some fields omitted
|
||||
}</pre><div class='docblock'><p>Used to create a representation of a command line program and all possible command line
|
||||
|
|
|
@ -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-8427' href='../src/clap/args/arg.rs.html#31-76'>[src]</a></span></h1>
|
||||
</span><a id='src-8286' href='../src/clap/args/arg.rs.html#31-76'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct Arg<'n, 'l, 'h, 'b, 'p, 'r> {
|
||||
// some fields omitted
|
||||
}</pre><div class='docblock'><p>The abstract representation of a command line argument used by the consumer of the library.
|
||||
|
|
|
@ -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-9287' href='../src/clap/args/argmatches.rs.html#57-68'>[src]</a></span></h1>
|
||||
</span><a id='src-9142' href='../src/clap/args/argmatches.rs.html#55-62'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct ArgMatches<'a> {
|
||||
// some fields omitted
|
||||
}</pre><div class='docblock'><p>Used to get information about the arguments that where supplied to the program at runtime by
|
||||
|
@ -100,7 +100,7 @@ prefer <code>values_of()</code> as <code>value_of()</code> will only return the
|
|||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"Value for output: {}"</span>, <span class='ident'>o</span>);
|
||||
}
|
||||
</pre>
|
||||
</div><h4 id='method.values_of' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.values_of' class='fnname'>values_of</a><'n>(&self, name: &'n <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>></code></h4>
|
||||
</div><h4 id='method.values_of' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.values_of' class='fnname'>values_of</a><'n>(&'a self, name: &'n <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>></code></h4>
|
||||
<div class='docblock'><p>Gets the values of a specific option or positional argument in a vector (i.e. an argument
|
||||
that takes multiple values at runtime). If the option wasn't present at runtime it
|
||||
returns <code>None</code></p>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<section id='main' class="content struct">
|
||||
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>clap</a>::<wbr><a class='struct' href=''>SubCommand</a><wbr></span><span class='out-of-band'><span id='render-detail'>
|
||||
<a id="collapse-all" href="#">[-]</a> <a id="expand-all" href="#">[+]</a>
|
||||
</span><a id='src-9778' href='../src/clap/args/subcommand.rs.html#23-26'>[src]</a></span></h1>
|
||||
</span><a id='src-9501' href='../src/clap/args/subcommand.rs.html#23-26'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct SubCommand<'a> {
|
||||
pub name: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a>,
|
||||
pub matches: <a class='struct' href='../clap/struct.ArgMatches.html' title='clap::ArgMatches'>ArgMatches</a><'a>,
|
||||
|
|
20
docs/main.js
20
docs/main.js
|
@ -78,9 +78,11 @@
|
|||
return;
|
||||
}
|
||||
|
||||
if (e.which === 191 && $('#help').hasClass('hidden')) { // question mark
|
||||
e.preventDefault();
|
||||
$('#help').removeClass('hidden');
|
||||
if (e.which === 191) { // question mark
|
||||
if (e.shiftKey && $('#help').hasClass('hidden')) {
|
||||
e.preventDefault();
|
||||
$('#help').removeClass('hidden');
|
||||
}
|
||||
} else if (e.which === 27) { // esc
|
||||
if (!$('#help').hasClass('hidden')) {
|
||||
e.preventDefault();
|
||||
|
@ -468,6 +470,8 @@
|
|||
if ($active.length) {
|
||||
document.location.href = $active.find('a').prop('href');
|
||||
}
|
||||
} else {
|
||||
$active.removeClass('highlighted');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -713,10 +717,12 @@
|
|||
if (crates[i] == window.currentCrate) {
|
||||
klass += ' current';
|
||||
}
|
||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
||||
div.append($('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'title': plainSummaryLine(desc),
|
||||
'class': klass}).text(crates[i]));
|
||||
if (rawSearchIndex[crates[i]].items[0]) {
|
||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
||||
div.append($('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'title': plainSummaryLine(desc),
|
||||
'class': klass}).text(crates[i]));
|
||||
}
|
||||
}
|
||||
sidebar.append(div);
|
||||
}
|
||||
|
|
|
@ -1369,10 +1369,6 @@
|
|||
<span id="1327">1327</span>
|
||||
<span id="1328">1328</span>
|
||||
<span id="1329">1329</span>
|
||||
<span id="1330">1330</span>
|
||||
<span id="1331">1331</span>
|
||||
<span id="1332">1332</span>
|
||||
<span id="1333">1333</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>collections</span>::<span class='ident'>BTreeMap</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>collections</span>::<span class='ident'>BTreeSet</span>;
|
||||
|
@ -1384,10 +1380,8 @@
|
|||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>process</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='ident'>Write</span>;
|
||||
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{ <span class='ident'>ArgMatches</span>, <span class='ident'>Arg</span>, <span class='ident'>SubCommand</span> };
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{<span class='ident'>FlagArg</span>, <span class='ident'>FlagBuilder</span>};
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{<span class='ident'>OptArg</span>, <span class='ident'>OptBuilder</span>};
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{<span class='ident'>PosArg</span>, <span class='ident'>PosBuilder</span>};
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{ <span class='ident'>ArgMatches</span>, <span class='ident'>Arg</span>, <span class='ident'>SubCommand</span>, <span class='ident'>MatchedArg</span>};
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::{ <span class='ident'>FlagBuilder</span>, <span class='ident'>OptBuilder</span>, <span class='ident'>PosBuilder</span>};
|
||||
|
||||
<span class='doccomment'>/// Used to create a representation of a command line program and all possible command line</span>
|
||||
<span class='doccomment'>/// arguments for parsing at runtime.</span>
|
||||
|
@ -2223,8 +2217,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>get_mut</span>(<span class='ident'>opt</span>.<span class='ident'>name</span>) {
|
||||
<span class='ident'>o</span>.<span class='ident'>values</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>get_mut</span>(<span class='ident'>opt</span>.<span class='ident'>name</span>) {
|
||||
<span class='comment'>// Options have values, so we can unwrap()</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'>vals</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>values</span> {
|
||||
<span class='ident'>vals</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
|
||||
}
|
||||
|
||||
<span class='comment'>// if it's multiple the occurrences are increased when originall found</span>
|
||||
<span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>opt</span>.<span class='ident'>multiple</span> { <span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>+</span> <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>1</span> };
|
||||
}
|
||||
|
@ -2285,10 +2283,12 @@
|
|||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>done</span> <span class='op'>=</span> <span class='boolval'>false</span>;
|
||||
<span class='kw'>if</span> <span class='ident'>p</span>.<span class='ident'>multiple</span> {
|
||||
<span class='comment'>// Check if it's already existing and update if so...</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'>pa</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>get_mut</span>(<span class='ident'>p</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='kw-2'>mut</span> <span class='ident'>pos</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>get_mut</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
|
||||
<span class='ident'>done</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
||||
<span class='ident'>pa</span>.<span class='ident'>occurrences</span> <span class='op'>+=</span> <span class='number'>1</span>;
|
||||
<span class='ident'>pa</span>.<span class='ident'>values</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
|
||||
<span class='ident'>pos</span>.<span class='ident'>occurrences</span> <span class='op'>+=</span> <span class='number'>1</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'>vals</span>) <span class='op'>=</span> <span class='ident'>pos</span>.<span class='ident'>values</span> {
|
||||
<span class='ident'>vals</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
|
||||
}
|
||||
}
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='comment'>// Only increment the positional counter if it doesn't allow multiples</span>
|
||||
|
@ -2296,10 +2296,10 @@
|
|||
}
|
||||
<span class='comment'>// Was an update made, or is this the first occurrence?</span>
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>done</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>{
|
||||
<span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>, <span class='ident'>MatchedArg</span>{
|
||||
<span class='ident'>name</span>: <span class='ident'>p</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>,
|
||||
<span class='ident'>values</span>: <span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg</span>.<span class='ident'>clone</span>()],
|
||||
<span class='ident'>values</span>: <span class='prelude-val'>Some</span>(<span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg</span>.<span class='ident'>clone</span>()]),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2319,9 +2319,7 @@
|
|||
<span class='comment'>// final required list</span>
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
}
|
||||
|
@ -2436,7 +2434,7 @@
|
|||
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument --{} was supplied more than once, but does not support multiple values"</span>, <span class='ident'>arg</span>), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
@ -2455,16 +2453,18 @@
|
|||
}
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>get_mut</span>(<span class='ident'>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='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>get_mut</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>+=</span> <span class='number'>1</span>;
|
||||
<span class='ident'>o</span>.<span class='ident'>values</span>.<span class='ident'>push</span>(<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</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'>vals</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>values</span> {
|
||||
<span class='ident'>vals</span>.<span class='ident'>push</span>(<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</span>());
|
||||
}
|
||||
}
|
||||
}
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
|
||||
<span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>MatchedArg</span>{
|
||||
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
||||
<span class='ident'>occurrences</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>0</span> },
|
||||
<span class='ident'>values</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</span>()]} <span class='kw'>else</span> {<span class='macro'>vec</span><span class='macro'>!</span>[]}
|
||||
<span class='ident'>values</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='prelude-val'>Some</span>(<span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</span>()])} <span class='kw'>else</span> { <span class='prelude-val'>Some</span>(<span class='macro'>vec</span><span class='macro'>!</span>[]) }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2482,9 +2482,7 @@
|
|||
<span class='comment'>// final required list</span>
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
}
|
||||
|
@ -2503,20 +2501,21 @@
|
|||
}
|
||||
|
||||
<span class='comment'>// Make sure this isn't one being added multiple times if it doesn't suppor it</span>
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument --{} was supplied more than once, but does not support multiple values"</span>, <span class='ident'>arg</span>), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span>
|
||||
<span class='ident'>done</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='kw-2'>mut</span> <span class='ident'>f</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>get_mut</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='kw-2'>mut</span> <span class='ident'>f</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>get_mut</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='ident'>done</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
||||
<span class='ident'>f</span>.<span class='ident'>occurrences</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='ident'>f</span>.<span class='ident'>occurrences</span> <span class='op'>+</span> <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>1</span> };
|
||||
}
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>done</span> {
|
||||
<span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>FlagArg</span>{
|
||||
<span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>MatchedArg</span>{
|
||||
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>,
|
||||
<span class='ident'>values</span>: <span class='prelude-val'>None</span>
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2536,9 +2535,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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
}
|
||||
|
@ -2582,16 +2579,16 @@
|
|||
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} was supplied more than once, but does not support multiple values"</span>, <span class='ident'>arg</span>), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
|
||||
<span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>MatchedArg</span>{
|
||||
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
||||
<span class='comment'>// occurrences will be incremented on getting a value</span>
|
||||
<span class='ident'>occurrences</span>: <span class='number'>0</span>,
|
||||
<span class='ident'>values</span>: <span class='macro'>vec</span><span class='macro'>!</span>[]
|
||||
<span class='ident'>values</span>: <span class='prelude-val'>Some</span>(<span class='macro'>vec</span><span class='macro'>!</span>[])
|
||||
});
|
||||
}
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
|
||||
|
@ -2608,9 +2605,7 @@
|
|||
<span class='comment'>// final required list</span>
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
}
|
||||
|
@ -2633,19 +2628,20 @@
|
|||
}
|
||||
|
||||
<span class='comment'>// Make sure this isn't one being added multiple times if it doesn't suppor it</span>
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>v</span>.<span class='ident'>multiple</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument -{} was supplied more than once, but does not support multiple values"</span>, <span class='ident'>arg</span>), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>done</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='kw-2'>mut</span> <span class='ident'>f</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>get_mut</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='kw-2'>mut</span> <span class='ident'>f</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>get_mut</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
||||
<span class='ident'>done</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
||||
<span class='ident'>f</span>.<span class='ident'>occurrences</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='ident'>f</span>.<span class='ident'>occurrences</span> <span class='op'>+</span> <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>1</span> };
|
||||
}
|
||||
<span class='kw'>if</span> <span class='op'>!</span><span class='ident'>done</span> {
|
||||
<span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>FlagArg</span>{
|
||||
<span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>MatchedArg</span>{
|
||||
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>
|
||||
<span class='ident'>occurrences</span>: <span class='number'>1</span>,
|
||||
<span class='ident'>values</span>: <span class='prelude-val'>None</span>
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2665,9 +2661,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'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
||||
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
||||
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
||||
}
|
||||
|
@ -2679,30 +2673,28 @@
|
|||
|
||||
<span class='kw'>fn</span> <span class='ident'>validate_blacklist</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>matches</span>: <span class='kw-2'>&</span><span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'ar</span><span class='op'>></span>) {
|
||||
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>iter</span>() {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} cannot be used with one or more of the other specified 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='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>s</span>)
|
||||
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"--{}"</span>, <span class='ident'>l</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'>flag</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>short</span>) <span class='op'>=</span> <span class='ident'>flag</span>.<span class='ident'>short</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>short</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'>long</span>) <span class='op'>=</span> <span class='ident'>flag</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> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\""</span>, <span class='ident'>flag</span>.<span class='ident'>name</span>)
|
||||
}
|
||||
} <span class='kw'>else</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'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>short</span>) <span class='op'>=</span> <span class='ident'>opt</span>.<span class='ident'>short</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>short</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'>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> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\""</span>, <span class='ident'>opt</span>.<span class='ident'>name</span>)
|
||||
}
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\""</span>, <span class='ident'>name</span>)
|
||||
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} cannot be used with one or more of the other specified 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='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"--{}"</span>, <span class='ident'>s</span>)
|
||||
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>l</span>)
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\""</span>, <span class='ident'>name</span>)
|
||||
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
||||
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" cannot be used with one or more of the other specified arguments"</span>,<span class='ident'>name</span>),
|
||||
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -684,7 +684,7 @@
|
|||
<span class='doccomment'>/// Arg::new("conifg")</span>
|
||||
<span class='doccomment'>/// # .short("c")</span>
|
||||
<span class='doccomment'>/// # ).get_matches();</span>
|
||||
<span class='attribute'>#[<span class='ident'>deprecated</span>(<span class='ident'>since</span> <span class='op'>=</span> <span class='string'>"0.5.15"</span>,
|
||||
<span class='attribute'>#[<span class='ident'>deprecated</span>(<span class='ident'>since</span> <span class='op'>=</span> <span class='string'>"0.6.0"</span>,
|
||||
<span class='ident'>reason</span> <span class='op'>=</span> <span class='string'>"use Arg::with_name() instead"</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>new</span>(<span class='ident'>n</span>: <span class='kw-2'>&</span><span class='lifetime'>'n</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>Arg</span><span class='op'><</span><span class='lifetime'>'n</span>, <span class='lifetime'>'l</span>, <span class='lifetime'>'h</span>, <span class='lifetime'>'b</span>, <span class='lifetime'>'p</span>, <span class='lifetime'>'r</span><span class='op'>></span> {
|
||||
<span class='ident'>Arg</span> {
|
||||
|
|
107
docs/src/clap/args/argbuilder/mod.rs.html
Normal file
107
docs/src/clap/args/argbuilder/mod.rs.html
Normal file
|
@ -0,0 +1,107 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="generator" content="rustdoc">
|
||||
<meta name="description" content="Source to the Rust file `src/args/argbuilder/mod.rs`.">
|
||||
<meta name="keywords" content="rust, rustlang, rust-lang">
|
||||
|
||||
<title>mod.rs.html -- source</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../../../../main.css">
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
<body class="rustdoc">
|
||||
<!--[if lte IE 8]>
|
||||
<div class="warning">
|
||||
This old browser is unsupported and will most likely display funky
|
||||
things.
|
||||
</div>
|
||||
<![endif]-->
|
||||
|
||||
|
||||
|
||||
<section class="sidebar">
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<nav class="sub">
|
||||
<form class="search-form js-only">
|
||||
<div class="search-container">
|
||||
<input class="search-input" name="search"
|
||||
autocomplete="off"
|
||||
placeholder="Click or press 'S' to search, '?' for more options..."
|
||||
type="search">
|
||||
</div>
|
||||
</form>
|
||||
</nav>
|
||||
|
||||
<section id='main' class="content source"><pre class="line-numbers"><span id="1">1</span>
|
||||
<span id="2">2</span>
|
||||
<span id="3">3</span>
|
||||
<span id="4">4</span>
|
||||
<span id="5">5</span>
|
||||
<span id="6">6</span>
|
||||
<span id="7">7</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>flag</span>::<span class='ident'>FlagBuilder</span>;
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>option</span>::<span class='ident'>OptBuilder</span>;
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>positional</span>::<span class='ident'>PosBuilder</span>;
|
||||
|
||||
<span class='kw'>mod</span> <span class='ident'>flag</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>positional</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>option</span>;
|
||||
</pre>
|
||||
</section>
|
||||
<section id='search' class="content hidden"></section>
|
||||
|
||||
<section class="footer"></section>
|
||||
|
||||
<div id="help" class="hidden">
|
||||
<div class="shortcuts">
|
||||
<h1>Keyboard shortcuts</h1>
|
||||
<dl>
|
||||
<dt>?</dt>
|
||||
<dd>Show this help dialog</dd>
|
||||
<dt>S</dt>
|
||||
<dd>Focus the search field</dd>
|
||||
<dt>⇤</dt>
|
||||
<dd>Move up in search results</dd>
|
||||
<dt>⇥</dt>
|
||||
<dd>Move down in search results</dd>
|
||||
<dt>⏎</dt>
|
||||
<dd>Go to active search result</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="infos">
|
||||
<h1>Search tricks</h1>
|
||||
<p>
|
||||
Prefix searches with a type followed by a colon (e.g.
|
||||
<code>fn:</code>) to restrict the search to a given type.
|
||||
</p>
|
||||
<p>
|
||||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||||
<code>struct</code>, <code>enum</code>,
|
||||
<code>trait</code>, <code>typedef</code> (or
|
||||
<code>tdef</code>).
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
window.rootPath = "../../../../";
|
||||
window.currentCrate = "clap";
|
||||
window.playgroundUrl = "";
|
||||
</script>
|
||||
<script src="../../../../jquery.js"></script>
|
||||
<script src="../../../../main.js"></script>
|
||||
|
||||
<script async src="../../../../search-index.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -305,38 +305,11 @@
|
|||
<span id="263">263</span>
|
||||
<span id="264">264</span>
|
||||
<span id="265">265</span>
|
||||
<span id="266">266</span>
|
||||
<span id="267">267</span>
|
||||
<span id="268">268</span>
|
||||
<span id="269">269</span>
|
||||
<span id="270">270</span>
|
||||
<span id="271">271</span>
|
||||
<span id="272">272</span>
|
||||
<span id="273">273</span>
|
||||
<span id="274">274</span>
|
||||
<span id="275">275</span>
|
||||
<span id="276">276</span>
|
||||
<span id="277">277</span>
|
||||
<span id="278">278</span>
|
||||
<span id="279">279</span>
|
||||
<span id="280">280</span>
|
||||
<span id="281">281</span>
|
||||
<span id="282">282</span>
|
||||
<span id="283">283</span>
|
||||
<span id="284">284</span>
|
||||
<span id="285">285</span>
|
||||
<span id="286">286</span>
|
||||
<span id="287">287</span>
|
||||
<span id="288">288</span>
|
||||
<span id="289">289</span>
|
||||
<span id="290">290</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>collections</span>::<span class='ident'>HashMap</span>;
|
||||
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::<span class='ident'>SubCommand</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::<span class='ident'>flagarg</span>::<span class='ident'>FlagArg</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::<span class='ident'>optarg</span>::<span class='ident'>OptArg</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::<span class='ident'>posarg</span>::<span class='ident'>PosArg</span>;
|
||||
<span class='kw'>use</span> <span class='ident'>args</span>::<span class='ident'>MatchedArg</span>;
|
||||
|
||||
<span class='doccomment'>/// Used to get information about the arguments that where supplied to the program at runtime by</span>
|
||||
<span class='doccomment'>/// the user. To get a new instance of this struct you use `.get_matches()` of the `App` struct.</span>
|
||||
|
@ -389,11 +362,7 @@
|
|||
<span class='doccomment'>/// }</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>struct</span> <span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'a</span><span class='op'>></span> {
|
||||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='ident'>flags</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='ident'>str</span>, <span class='ident'>FlagArg</span><span class='op'>></span>,
|
||||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='ident'>opts</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='ident'>str</span>, <span class='ident'>OptArg</span><span class='op'>></span>,
|
||||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='ident'>positionals</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='ident'>str</span>, <span class='ident'>PosArg</span><span class='op'>></span>,
|
||||
<span class='kw'>pub</span> <span class='ident'>args</span>: <span class='ident'>HashMap</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='ident'>str</span>, <span class='ident'>MatchedArg</span><span class='op'>></span>,
|
||||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='ident'>subcommand</span>: <span class='prelude-ty'>Option</span><span class='op'><</span><span class='ident'>Box</span><span class='op'><</span><span class='ident'>SubCommand</span><span class='op'><</span><span class='lifetime'>'a</span><span class='op'>>></span><span class='op'>></span>,
|
||||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
|
@ -413,10 +382,7 @@
|
|||
<span class='attribute'>#[<span class='ident'>doc</span>(<span class='ident'>hidden</span>)]</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>new</span>() <span class='op'>-></span> <span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'a</span><span class='op'>></span> {
|
||||
<span class='ident'>ArgMatches</span> {
|
||||
<span class='comment'>// matches_of: name,</span>
|
||||
<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</span>: <span class='ident'>HashMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>args</span>: <span class='ident'>HashMap</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>subcommand</span>: <span class='prelude-val'>None</span>,
|
||||
<span class='ident'>usage</span>: <span class='prelude-val'>None</span>
|
||||
}
|
||||
|
@ -439,14 +405,11 @@
|
|||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>value_of</span><span class='op'><</span><span class='lifetime'>'n</span><span class='op'>></span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'n</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='prelude-ty'>Option</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></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'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>opt</span>.<span class='ident'>values</span>.<span class='ident'>iter</span>().<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>&</span><span class='ident'>s</span>[..]);
|
||||
}
|
||||
}
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>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'>s</span>) <span class='op'>=</span> <span class='ident'>pos</span>.<span class='ident'>values</span>.<span class='ident'>iter</span>().<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>&</span><span class='ident'>s</span>[..]);
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>arg</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>args</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'>vals</span>) <span class='op'>=</span> <span class='ident'>arg</span>.<span class='ident'>values</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'>val</span>) <span class='op'>=</span> <span class='ident'>vals</span>.<span class='ident'>iter</span>().<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>&</span><span class='ident'>val</span>[..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='prelude-val'>None</span>
|
||||
|
@ -470,16 +433,11 @@
|
|||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>values_of</span><span class='op'><</span><span class='lifetime'>'n</span><span class='op'>></span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'n</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='prelude-ty'>Option</span><span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>>></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'>name</span>) {
|
||||
<span class='kw'>if</span> <span class='ident'>opt</span>.<span class='ident'>values</span>.<span class='ident'>is_empty</span>() { <span class='kw'>return</span> <span class='prelude-val'>None</span>; }
|
||||
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='ident'>opt</span>.<span class='ident'>values</span>.<span class='ident'>iter</span>().<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>s</span><span class='op'>|</span> <span class='kw-2'>&</span><span class='ident'>s</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='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='ident'>pos</span>.<span class='ident'>values</span>.<span class='ident'>is_empty</span>() { <span class='kw'>return</span> <span class='prelude-val'>None</span>; }
|
||||
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='ident'>pos</span>.<span class='ident'>values</span>.<span class='ident'>iter</span>().<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>s</span><span class='op'>|</span> <span class='kw-2'>&</span><span class='ident'>s</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='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>values_of</span><span class='op'><</span><span class='lifetime'>'n</span><span class='op'>></span>(<span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'n</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='prelude-ty'>Option</span><span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'a</span> <span class='ident'>str</span><span class='op'>>></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'>arg</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>args</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'>vals</span>) <span class='op'>=</span> <span class='ident'>arg</span>.<span class='ident'>values</span> {
|
||||
<span class='kw'>return</span> <span class='prelude-val'>Some</span>(<span class='ident'>vals</span>.<span class='ident'>iter</span>().<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>s</span><span class='op'>|</span> <span class='kw-2'>&</span><span class='ident'>s</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='prelude-val'>None</span>
|
||||
}
|
||||
|
@ -500,9 +458,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'>sc</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>subcommand</span> {
|
||||
<span class='kw'>if</span> <span class='ident'>sc</span>.<span class='ident'>name</span> <span class='op'>==</span> <span class='ident'>name</span> { <span class='kw'>return</span> <span class='boolval'>true</span>; }
|
||||
}
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {<span class='kw'>return</span> <span class='boolval'>true</span>;}
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {<span class='kw'>return</span> <span class='boolval'>true</span>;}
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {<span class='kw'>return</span> <span class='boolval'>true</span>;}
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>args</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {<span class='kw'>return</span> <span class='boolval'>true</span>;}
|
||||
<span class='boolval'>false</span>
|
||||
}
|
||||
|
||||
|
@ -523,14 +479,8 @@
|
|||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>occurrences_of</span><span class='op'><</span><span class='lifetime'>'n</span><span class='op'>></span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>name</span>: <span class='kw-2'>&</span><span class='lifetime'>'n</span> <span class='ident'>str</span>) <span class='op'>-></span> <span class='ident'>u8</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'>f</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>return</span> <span class='ident'>f</span>.<span class='ident'>occurrences</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'>o</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>return</span> <span class='ident'>o</span>.<span class='ident'>occurrences</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</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>return</span> <span class='ident'>p</span>.<span class='ident'>occurrences</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'>arg</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>args</span>.<span class='ident'>get</span>(<span class='ident'>name</span>) {
|
||||
<span class='kw'>return</span> <span class='ident'>arg</span>.<span class='ident'>occurrences</span>;
|
||||
}
|
||||
<span class='number'>0</span>
|
||||
}
|
||||
|
|
|
@ -51,22 +51,18 @@
|
|||
<span id="9"> 9</span>
|
||||
<span id="10">10</span>
|
||||
<span id="11">11</span>
|
||||
<span id="12">12</span>
|
||||
<span id="13">13</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>arg</span>::<span class='ident'>Arg</span>;
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>argmatches</span>::<span class='ident'>ArgMatches</span>;
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>subcommand</span>::<span class='ident'>SubCommand</span>;
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>flagarg</span>::{<span class='ident'>FlagArg</span>, <span class='ident'>FlagBuilder</span>};
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>optarg</span>::{<span class='ident'>OptArg</span>, <span class='ident'>OptBuilder</span>};
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>posarg</span>::{<span class='ident'>PosArg</span>, <span class='ident'>PosBuilder</span>};
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>argbuilder</span>::{<span class='ident'>FlagBuilder</span>, <span class='ident'>OptBuilder</span>, <span class='ident'>PosBuilder</span>};
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='self'>self</span>::<span class='ident'>matchedarg</span>::<span class='ident'>MatchedArg</span>;
|
||||
|
||||
<span class='kw'>mod</span> <span class='ident'>arg</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>argmatches</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>subcommand</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>flagarg</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>optarg</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>posarg</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>argbuilder</span>;
|
||||
<span class='kw'>mod</span> <span class='ident'>matchedarg</span>;
|
||||
</pre>
|
||||
</section>
|
||||
<section id='search' class="content hidden"></section>
|
||||
|
|
|
@ -998,7 +998,7 @@
|
|||
<span class='doccomment'>//! * **Specific Value Sets**: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a `--mode` option which may *only* have one of two values `fast` or `slow` such as `--mode fast` or `--mode slow`)</span>
|
||||
<span class='doccomment'>//! * **Default Values**: Although not specifically provided by `clap` you can achieve this exact functionality from Rust's `Option<&str>.unwrap_or("some default")` method (or `Result<T,String>.unwrap_or(T)` when using typed values)</span>
|
||||
<span class='doccomment'>//! * **Automatic Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically setting the version of your application to the version in your Cargo.toml. See `examples/09_AutoVersion.rs` for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)</span>
|
||||
<span class='doccomment'>//! * **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr` in order to use with the other `clap` macros. See `examples/13a_EnumValuesAutomatic.rs` for details.</span>
|
||||
<span class='doccomment'>//! * **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details.</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
<span class='doccomment'>//! ## Quick Example</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
|
|
Loading…
Reference in a new issue