mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
docs(clap): rebuild documentation with new value_t macros
This commit is contained in:
parent
90b7e76091
commit
1b06a0c56c
12 changed files with 846 additions and 10 deletions
|
@ -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-901'>[src]</a></span></h1>
|
||||
</span><a id='src-0' href='../src/clap/lib.rs.html#1-902'>[src]</a></span></h1>
|
||||
<div class='docblock'>
|
||||
<h1 id="clap" class='section-header'><a
|
||||
href="#clap">clap</a></h1>
|
||||
|
@ -123,6 +123,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</li>
|
||||
<li><strong>Get Version from Cargo.toml</strong>: <code>clap</code> is fully compatible with Rust's <code>env!()</code> macro for automatically getting the version from 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.) so long as the type you request implements <code>std::fmt::FrmStr</code> See the <code>examples/12_TypedValues.rs</code> or the documentation for more information.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="quick-example" class='section-header'><a
|
||||
|
@ -355,7 +356,27 @@ SUBCOMMANDS:
|
|||
<h2 id="license" class='section-header'><a
|
||||
href="#license">License</a></h2>
|
||||
<p><code>clap</code> is licensed under the MIT license. Please the LICENSE-MIT file in this repository for more information.</p>
|
||||
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||||
</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td><a class='stability Unmarked' title='No stability level'></a><a class='macro' href='macro.value_t!.html'
|
||||
title='clap::value_t!'>value_t!</a></td>
|
||||
<td class='docblock short'><p>Convenience macro getting a typed value <code>T</code> where <code>T</code> implements <code>std::fmt::FrmStr</code>
|
||||
This macro returns a <code>Result<T,String></code> 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). </p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><a class='stability Unmarked' title='No stability level'></a><a class='macro' href='macro.value_t_or_exit!.html'
|
||||
title='clap::value_t_or_exit!'>value_t_or_exit!</a></td>
|
||||
<td class='docblock short'><p>Convenience macro getting a typed value <code>T</code> where <code>T</code> implements <code>std::fmt::FrmStr</code>
|
||||
This macro returns a <code>T</code> or <code>Vec<T></code> or exits with a usage string upon failure. This
|
||||
removes some of the boiler plate to handle failures from value_t! above. </p>
|
||||
</td>
|
||||
</tr>
|
||||
</table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td><a class='stability Unmarked' title='No stability level'></a><a class='struct' href='struct.App.html'
|
||||
|
|
161
docs/clap/macro.value_t!.html
Normal file
161
docs/clap/macro.value_t!.html
Normal file
|
@ -0,0 +1,161 @@
|
|||
<!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="API documentation for the Rust `value_t!` macro in crate `clap`.">
|
||||
<meta name="keywords" content="rust, rustlang, rust-lang, value_t!">
|
||||
|
||||
<title>clap::value_t! - Rust</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">
|
||||
|
||||
<p class='location'><a href='index.html'>clap</a></p><script>window.sidebarCurrent = {name: 'value_t!', ty: 'macro', relpath: ''};</script><script defer src="sidebar-items.js"></script>
|
||||
</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 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#76-110'>[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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>match</span> <span class='ident'>v</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>val</span>) <span class='op'>=></span> <span class='prelude-val'>Ok</span>(<span class='ident'>val</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}"</span>,<span class='ident'>v</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>))),
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found"</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>))
|
||||
}
|
||||
};
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>values_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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>values_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>tmp</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>v</span>.<span class='ident'>len</span>());
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>err</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
|
||||
<span class='kw'>for</span> <span class='ident'>pv</span> <span class='kw'>in</span> <span class='ident'>v</span> {
|
||||
<span class='kw'>match</span> <span class='ident'>pv</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>rv</span>) <span class='op'>=></span> <span class='ident'>tmp</span>.<span class='ident'>push</span>(<span class='ident'>rv</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='ident'>err</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}"</span>,<span class='ident'>pv</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>)));
|
||||
<span class='kw'>break</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='kw'>match</span> <span class='ident'>err</span> {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>e</span>) <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='ident'>e</span>),
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Ok</span>(<span class='ident'>tmp</span>)
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found"</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>))
|
||||
}
|
||||
};
|
||||
}
|
||||
</pre>
|
||||
<div class='docblock'><p>Convenience macro getting a typed value <code>T</code> where <code>T</code> implements <code>std::fmt::FrmStr</code>
|
||||
This macro returns a <code>Result<T,String></code> 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). </p>
|
||||
|
||||
<p>You can use it to get a single value, or a <code>Vec<T></code> with the <code>values_of()</code></p>
|
||||
|
||||
<p><strong>NOTE:</strong> Be cautious, as since this a macro invocation it's not exactly like
|
||||
standard syntax.</p>
|
||||
|
||||
<p># Example single value</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='kw'>let</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"myapp"</span>)
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"[length] 'Set the length to use as a positive whole number, i.e. 20'"</span>)
|
||||
.<span class='ident'>get_matches</span>();
|
||||
<span class='kw'>let</span> <span class='ident'>len</span> <span class='op'>=</span> <span class='macro'>value_t</span><span class='macro'>!</span>(<span class='ident'>matches</span>.<span class='ident'>value_of</span>(<span class='string'>"length"</span>), <span class='ident'>u32</span>).<span class='ident'>unwrap_or_else</span>(<span class='op'>|</span><span class='ident'>e</span><span class='op'>|</span>{<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}"</span>,<span class='ident'>e</span>); <span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>)});
|
||||
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} + 2: {}"</span>, <span class='ident'>len</span>, <span class='ident'>len</span> <span class='op'>+</span> <span class='number'>2</span>);
|
||||
</pre>
|
||||
|
||||
<p># Example multiple values</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='kw'>let</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"myapp"</span>)
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"[seq]... 'A sequence of positive whole numbers, i.e. 20 30 45'"</span>)
|
||||
.<span class='ident'>get_matches</span>();
|
||||
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='macro'>value_t</span><span class='macro'>!</span>(<span class='ident'>matches</span>.<span class='ident'>values_of</span>(<span class='string'>"seq"</span>), <span class='ident'>u32</span>).<span class='ident'>unwrap_or_else</span>(<span class='op'>|</span><span class='ident'>e</span><span class='op'>|</span>{<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}"</span>,<span class='ident'>e</span>); <span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>)}) {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} + 2: {}"</span>, <span class='ident'>v</span>, <span class='ident'>v</span> <span class='op'>+</span> <span class='number'>2</span>);
|
||||
}
|
||||
</pre>
|
||||
</div></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>
|
168
docs/clap/macro.value_t_or_exit!.html
Normal file
168
docs/clap/macro.value_t_or_exit!.html
Normal file
|
@ -0,0 +1,168 @@
|
|||
<!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="API documentation for the Rust `value_t_or_exit!` macro in crate `clap`.">
|
||||
<meta name="keywords" content="rust, rustlang, rust-lang, value_t_or_exit!">
|
||||
|
||||
<title>clap::value_t_or_exit! - Rust</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">
|
||||
|
||||
<p class='location'><a href='index.html'>clap</a></p><script>window.sidebarCurrent = {name: 'value_t_or_exit!', ty: 'macro', relpath: ''};</script><script defer src="sidebar-items.js"></script>
|
||||
</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 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#158-197'>[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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>match</span> <span class='ident'>v</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>val</span>) <span class='op'>=></span> <span class='ident'>val</span>,
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}\n{}\nPlease re-run with --help for more information"</span>,<span class='ident'>v</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information"</span>,<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
};
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>values_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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>values_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>tmp</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>v</span>.<span class='ident'>len</span>());
|
||||
<span class='kw'>for</span> <span class='ident'>pv</span> <span class='kw'>in</span> <span class='ident'>v</span> {
|
||||
<span class='kw'>match</span> <span class='ident'>pv</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>rv</span>) <span class='op'>=></span> <span class='ident'>tmp</span>.<span class='ident'>push</span>(<span class='ident'>rv</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}\n{}\nPlease re-run with --help for more information"</span>,<span class='ident'>pv</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='ident'>tmp</span>
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information"</span>,<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
</pre>
|
||||
<div class='docblock'><p>Convenience macro getting a typed value <code>T</code> where <code>T</code> implements <code>std::fmt::FrmStr</code>
|
||||
This macro returns a <code>T</code> or <code>Vec<T></code> or exits with a usage string upon failure. This
|
||||
removes some of the boiler plate to handle failures from value_t! above. </p>
|
||||
|
||||
<p>You can use it to get a single value <code>T</code>, or a <code>Vec<T></code> with the <code>values_of()</code></p>
|
||||
|
||||
<p><strong>NOTE:</strong> This should only be used on required arguments, as it can be confusing to the user
|
||||
why they are getting error messages when it appears they're entering all required argumetns.</p>
|
||||
|
||||
<p><strong>NOTE:</strong> Be cautious, as since this a macro invocation it's not exactly like
|
||||
standard syntax.</p>
|
||||
|
||||
<p># Example single value</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='kw'>let</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"myapp"</span>)
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"[length] 'Set the length to use as a positive whole number, i.e. 20'"</span>)
|
||||
.<span class='ident'>get_matches</span>();
|
||||
<span class='kw'>let</span> <span class='ident'>len</span> <span class='op'>=</span> <span class='macro'>value_t_or_exit</span><span class='macro'>!</span>(<span class='ident'>matches</span>.<span class='ident'>value_of</span>(<span class='string'>"length"</span>), <span class='ident'>u32</span>);
|
||||
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} + 2: {}"</span>, <span class='ident'>len</span>, <span class='ident'>len</span> <span class='op'>+</span> <span class='number'>2</span>);
|
||||
</pre>
|
||||
|
||||
<p># Example multiple values</p>
|
||||
<pre id='rust-example-rendered' class='rust '>
|
||||
<span class='kw'>let</span> <span class='ident'>matches</span> <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"myapp"</span>)
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"[seq]... 'A sequence of positive whole numbers, i.e. 20 30 45'"</span>)
|
||||
.<span class='ident'>get_matches</span>();
|
||||
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='macro'>value_t_or_exit</span><span class='macro'>!</span>(<span class='ident'>matches</span>.<span class='ident'>values_of</span>(<span class='string'>"seq"</span>), <span class='ident'>u32</span>) {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} + 2: {}"</span>, <span class='ident'>v</span>, <span class='ident'>v</span> <span class='op'>+</span> <span class='number'>2</span>);
|
||||
}
|
||||
</pre>
|
||||
</div></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>
|
|
@ -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."]]});
|
||||
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":[["value_t!","Convenience macro getting a typed value `T` where `T` implements `std::fmt::FrmStr` 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::fmt::FrmStr` 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. "]]});
|
|
@ -1 +1 @@
|
|||
{"name":"clap","counts":{"deprecated":0,"unstable":0,"stable":0,"unmarked":45},"submodules":[]}
|
||||
{"name":"clap","counts":{"deprecated":0,"unstable":0,"stable":0,"unmarked":47},"submodules":[]}
|
|
@ -181,7 +181,7 @@ function just like apps, in that they get their own auto generated help, version
|
|||
href="#example">Example</a></h1><pre id='rust-example-rendered' class='rust '>
|
||||
.<span class='ident'>subcommand</span>(<span class='ident'>SubCommand</span>::<span class='ident'>new</span>(<span class='string'>"config"</span>)
|
||||
.<span class='ident'>about</span>(<span class='string'>"Controls configuration features"</span>)
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"<config> 'Required configuration file to use'"</span>)))
|
||||
.<span class='ident'>arg_from_usage</span>(<span class='string'>"<config> 'Required configuration file to use'"</span>))
|
||||
<span class='comment'>// Additional subcommand configuration goes here, such as other arguments...</span>
|
||||
</pre>
|
||||
</div><h4 id='method.subcommands' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.subcommands' class='fnname'>subcommands</a>(self, subcmds: <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.App.html' title='clap::App'>App</a><'a, 'v, 'ab, 'u, 'ar>>) -> <a class='struct' href='../clap/struct.App.html' title='clap::App'>App</a><'a, 'v, 'ab, 'u, 'ar></code></h4>
|
||||
|
|
|
@ -143,7 +143,6 @@ specify one) i.e. all arguments without a <code>short</code> or <code>long</code
|
|||
<span class='comment'>// A required positional argument named "input"</span>
|
||||
<span class='ident'>Arg</span>::<span class='ident'>from_usage</span>(<span class='string'>"<input> 'the input file to use'"</span>)
|
||||
])
|
||||
<span class='attribute'>#
|
||||
</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>(self, s: &<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><'n, 'l, 'h, 'b, 'p, 'r></code></h4>
|
||||
<div class='docblock'><p>Sets the short version of the argument without the preceding <code>-</code>.</p>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1822,7 +1822,7 @@
|
|||
<span class='doccomment'>/// # let app = App::new("myprog")</span>
|
||||
<span class='doccomment'>/// .subcommand(SubCommand::new("config")</span>
|
||||
<span class='doccomment'>/// .about("Controls configuration features")</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("<config> 'Required configuration file to use'")))</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("<config> 'Required configuration file to use'"))</span>
|
||||
<span class='doccomment'>/// // Additional subcommand configuration goes here, such as other arguments...</span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
|
|
|
@ -584,7 +584,6 @@
|
|||
<span id="542">542</span>
|
||||
<span id="543">543</span>
|
||||
<span id="544">544</span>
|
||||
<span id="545">545</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>use</span> <span class='ident'>usageparser</span>::{<span class='ident'>UsageParser</span>, <span class='ident'>UsageToken</span>};
|
||||
|
||||
|
@ -784,7 +783,6 @@
|
|||
<span class='doccomment'>/// // A required positional argument named "input"</span>
|
||||
<span class='doccomment'>/// Arg::from_usage("<input> 'the input file to use'")</span>
|
||||
<span class='doccomment'>/// ])</span>
|
||||
<span class='doccomment'>/// # </span>
|
||||
<span class='doccomment'>/// # .get_matches();</span>
|
||||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>from_usage</span>(<span class='ident'>u</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'>'n</span>, <span class='lifetime'>'n</span>, <span class='lifetime'>'b</span>, <span class='lifetime'>'p</span>, <span class='lifetime'>'r</span><span class='op'>></span> {
|
||||
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>u</span>.<span class='ident'>len</span>() <span class='op'>></span> <span class='number'>0</span>, <span class='string'>"Arg::from_usage() requires a non-zero-length usage string but none was provided"</span>);
|
||||
|
|
|
@ -941,6 +941,7 @@
|
|||
<span id="899">899</span>
|
||||
<span id="900">900</span>
|
||||
<span id="901">901</span>
|
||||
<span id="902">902</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>
|
||||
|
||||
|
@ -1001,6 +1002,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</span>
|
||||
<span class='doccomment'>//! * **Get Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically getting the version from 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.) so long as the type you request implements `std::fmt::FrmStr` See the `examples/12_TypedValues.rs` or the documentation for more information.</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
<span class='doccomment'>//! ## Quick Example</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
|
|
487
docs/src/clap/macros.rs.html
Normal file
487
docs/src/clap/macros.rs.html
Normal file
|
@ -0,0 +1,487 @@
|
|||
<!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/macros.rs`.">
|
||||
<meta name="keywords" content="rust, rustlang, rust-lang">
|
||||
|
||||
<title>macros.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>
|
||||
<span id="8"> 8</span>
|
||||
<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>
|
||||
<span id="14"> 14</span>
|
||||
<span id="15"> 15</span>
|
||||
<span id="16"> 16</span>
|
||||
<span id="17"> 17</span>
|
||||
<span id="18"> 18</span>
|
||||
<span id="19"> 19</span>
|
||||
<span id="20"> 20</span>
|
||||
<span id="21"> 21</span>
|
||||
<span id="22"> 22</span>
|
||||
<span id="23"> 23</span>
|
||||
<span id="24"> 24</span>
|
||||
<span id="25"> 25</span>
|
||||
<span id="26"> 26</span>
|
||||
<span id="27"> 27</span>
|
||||
<span id="28"> 28</span>
|
||||
<span id="29"> 29</span>
|
||||
<span id="30"> 30</span>
|
||||
<span id="31"> 31</span>
|
||||
<span id="32"> 32</span>
|
||||
<span id="33"> 33</span>
|
||||
<span id="34"> 34</span>
|
||||
<span id="35"> 35</span>
|
||||
<span id="36"> 36</span>
|
||||
<span id="37"> 37</span>
|
||||
<span id="38"> 38</span>
|
||||
<span id="39"> 39</span>
|
||||
<span id="40"> 40</span>
|
||||
<span id="41"> 41</span>
|
||||
<span id="42"> 42</span>
|
||||
<span id="43"> 43</span>
|
||||
<span id="44"> 44</span>
|
||||
<span id="45"> 45</span>
|
||||
<span id="46"> 46</span>
|
||||
<span id="47"> 47</span>
|
||||
<span id="48"> 48</span>
|
||||
<span id="49"> 49</span>
|
||||
<span id="50"> 50</span>
|
||||
<span id="51"> 51</span>
|
||||
<span id="52"> 52</span>
|
||||
<span id="53"> 53</span>
|
||||
<span id="54"> 54</span>
|
||||
<span id="55"> 55</span>
|
||||
<span id="56"> 56</span>
|
||||
<span id="57"> 57</span>
|
||||
<span id="58"> 58</span>
|
||||
<span id="59"> 59</span>
|
||||
<span id="60"> 60</span>
|
||||
<span id="61"> 61</span>
|
||||
<span id="62"> 62</span>
|
||||
<span id="63"> 63</span>
|
||||
<span id="64"> 64</span>
|
||||
<span id="65"> 65</span>
|
||||
<span id="66"> 66</span>
|
||||
<span id="67"> 67</span>
|
||||
<span id="68"> 68</span>
|
||||
<span id="69"> 69</span>
|
||||
<span id="70"> 70</span>
|
||||
<span id="71"> 71</span>
|
||||
<span id="72"> 72</span>
|
||||
<span id="73"> 73</span>
|
||||
<span id="74"> 74</span>
|
||||
<span id="75"> 75</span>
|
||||
<span id="76"> 76</span>
|
||||
<span id="77"> 77</span>
|
||||
<span id="78"> 78</span>
|
||||
<span id="79"> 79</span>
|
||||
<span id="80"> 80</span>
|
||||
<span id="81"> 81</span>
|
||||
<span id="82"> 82</span>
|
||||
<span id="83"> 83</span>
|
||||
<span id="84"> 84</span>
|
||||
<span id="85"> 85</span>
|
||||
<span id="86"> 86</span>
|
||||
<span id="87"> 87</span>
|
||||
<span id="88"> 88</span>
|
||||
<span id="89"> 89</span>
|
||||
<span id="90"> 90</span>
|
||||
<span id="91"> 91</span>
|
||||
<span id="92"> 92</span>
|
||||
<span id="93"> 93</span>
|
||||
<span id="94"> 94</span>
|
||||
<span id="95"> 95</span>
|
||||
<span id="96"> 96</span>
|
||||
<span id="97"> 97</span>
|
||||
<span id="98"> 98</span>
|
||||
<span id="99"> 99</span>
|
||||
<span id="100">100</span>
|
||||
<span id="101">101</span>
|
||||
<span id="102">102</span>
|
||||
<span id="103">103</span>
|
||||
<span id="104">104</span>
|
||||
<span id="105">105</span>
|
||||
<span id="106">106</span>
|
||||
<span id="107">107</span>
|
||||
<span id="108">108</span>
|
||||
<span id="109">109</span>
|
||||
<span id="110">110</span>
|
||||
<span id="111">111</span>
|
||||
<span id="112">112</span>
|
||||
<span id="113">113</span>
|
||||
<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>
|
||||
<span id="137">137</span>
|
||||
<span id="138">138</span>
|
||||
<span id="139">139</span>
|
||||
<span id="140">140</span>
|
||||
<span id="141">141</span>
|
||||
<span id="142">142</span>
|
||||
<span id="143">143</span>
|
||||
<span id="144">144</span>
|
||||
<span id="145">145</span>
|
||||
<span id="146">146</span>
|
||||
<span id="147">147</span>
|
||||
<span id="148">148</span>
|
||||
<span id="149">149</span>
|
||||
<span id="150">150</span>
|
||||
<span id="151">151</span>
|
||||
<span id="152">152</span>
|
||||
<span id="153">153</span>
|
||||
<span id="154">154</span>
|
||||
<span id="155">155</span>
|
||||
<span id="156">156</span>
|
||||
<span id="157">157</span>
|
||||
<span id="158">158</span>
|
||||
<span id="159">159</span>
|
||||
<span id="160">160</span>
|
||||
<span id="161">161</span>
|
||||
<span id="162">162</span>
|
||||
<span id="163">163</span>
|
||||
<span id="164">164</span>
|
||||
<span id="165">165</span>
|
||||
<span id="166">166</span>
|
||||
<span id="167">167</span>
|
||||
<span id="168">168</span>
|
||||
<span id="169">169</span>
|
||||
<span id="170">170</span>
|
||||
<span id="171">171</span>
|
||||
<span id="172">172</span>
|
||||
<span id="173">173</span>
|
||||
<span id="174">174</span>
|
||||
<span id="175">175</span>
|
||||
<span id="176">176</span>
|
||||
<span id="177">177</span>
|
||||
<span id="178">178</span>
|
||||
<span id="179">179</span>
|
||||
<span id="180">180</span>
|
||||
<span id="181">181</span>
|
||||
<span id="182">182</span>
|
||||
<span id="183">183</span>
|
||||
<span id="184">184</span>
|
||||
<span id="185">185</span>
|
||||
<span id="186">186</span>
|
||||
<span id="187">187</span>
|
||||
<span id="188">188</span>
|
||||
<span id="189">189</span>
|
||||
<span id="190">190</span>
|
||||
<span id="191">191</span>
|
||||
<span id="192">192</span>
|
||||
<span id="193">193</span>
|
||||
<span id="194">194</span>
|
||||
<span id="195">195</span>
|
||||
<span id="196">196</span>
|
||||
<span id="197">197</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='comment'>// De-duplication macro used in src/app.rs</span>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>get_help</span> {
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>opt</span>:<span class='ident'>ident</span>) <span class='op'>=></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='macro-nonterminal'>$</span><span class='macro-nonterminal'>opt</span>.<span class='ident'>help</span> {
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>, <span class='ident'>h</span>,
|
||||
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>pv</span>) <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>opt</span>.<span class='ident'>possible_vals</span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>pv_s</span> <span class='op'>=</span> <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>with_capacity</span>(<span class='number'>50</span>), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..]);
|
||||
<span class='ident'>pv_s</span>.<span class='ident'>shrink_to_fit</span>();
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" [values:{}]"</span>, <span class='kw-2'>&</span><span class='ident'>pv_s</span>[..])
|
||||
}<span class='kw'>else</span>{<span class='string'>""</span>.<span class='ident'>to_owned</span>()})
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='string'>" "</span>.<span class='ident'>to_owned</span>()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
<span class='comment'>// Thanks to bluss and flan3002 in #rust IRC</span>
|
||||
<span class='comment'>//</span>
|
||||
<span class='comment'>// Helps with rightward drift when iterating over something and matching each item.</span>
|
||||
<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>for_match</span> {
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>it</span>:<span class='ident'>ident</span>, $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>p</span>:<span class='ident'>pat</span> <span class='op'>=></span> $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>e</span>:<span class='ident'>expr</span>);<span class='op'>+</span>),<span class='op'>*</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>for</span> <span class='ident'>i</span> <span class='kw'>in</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>it</span> {
|
||||
<span class='kw'>match</span> <span class='ident'>i</span> {
|
||||
$(
|
||||
<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>p</span> <span class='op'>=></span> { $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>e</span>)<span class='op'>+</span> }
|
||||
)<span class='op'>*</span>
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
<span class='doccomment'>/// Convenience macro getting a typed value `T` where `T` implements `std::fmt::FrmStr`</span>
|
||||
<span class='doccomment'>/// This macro returns a `Result<T,String>` which allows you as the developer to decide</span>
|
||||
<span class='doccomment'>/// what you'd like to do on a failed parse. There are two types of errors, parse failures</span>
|
||||
<span class='doccomment'>/// and those where the argument wasn't present (such as a non-required argument). </span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// You can use it to get a single value, or a `Vec<T>` with the `values_of()`</span>
|
||||
<span class='doccomment'>/// </span>
|
||||
<span class='doccomment'>/// **NOTE:** Be cautious, as since this a macro invocation it's not exactly like</span>
|
||||
<span class='doccomment'>/// standard syntax.</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// # Example single value</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// ```no_run</span>
|
||||
<span class='doccomment'>/// # #[macro_use]</span>
|
||||
<span class='doccomment'>/// # extern crate clap;</span>
|
||||
<span class='doccomment'>/// # use clap::App;</span>
|
||||
<span class='doccomment'>/// # fn main() {</span>
|
||||
<span class='doccomment'>/// let matches = App::new("myapp")</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("[length] 'Set the length to use as a positive whole number, i.e. 20'")</span>
|
||||
<span class='doccomment'>/// .get_matches();</span>
|
||||
<span class='doccomment'>/// let len = value_t!(matches.value_of("length"), u32).unwrap_or_else(|e|{println!("{}",e); std::process::exit(1)});</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// println!("{} + 2: {}", len, len + 2);</span>
|
||||
<span class='doccomment'>/// # }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// # Example multiple values</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// ```no_run</span>
|
||||
<span class='doccomment'>/// # #[macro_use]</span>
|
||||
<span class='doccomment'>/// # extern crate clap;</span>
|
||||
<span class='doccomment'>/// # use clap::App;</span>
|
||||
<span class='doccomment'>/// # fn main() {</span>
|
||||
<span class='doccomment'>/// let matches = App::new("myapp")</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("[seq]... 'A sequence of positive whole numbers, i.e. 20 30 45'")</span>
|
||||
<span class='doccomment'>/// .get_matches();</span>
|
||||
<span class='doccomment'>/// for v in value_t!(matches.values_of("seq"), u32).unwrap_or_else(|e|{println!("{}",e); std::process::exit(1)}) {</span>
|
||||
<span class='doccomment'>/// println!("{} + 2: {}", v, v + 2);</span>
|
||||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// # }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='attribute'>#[<span class='ident'>macro_export</span>]</span>
|
||||
<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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>match</span> <span class='ident'>v</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>val</span>) <span class='op'>=></span> <span class='prelude-val'>Ok</span>(<span class='ident'>val</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}"</span>,<span class='ident'>v</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>))),
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found"</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>))
|
||||
}
|
||||
};
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>values_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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>values_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>tmp</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>v</span>.<span class='ident'>len</span>());
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>err</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
|
||||
<span class='kw'>for</span> <span class='ident'>pv</span> <span class='kw'>in</span> <span class='ident'>v</span> {
|
||||
<span class='kw'>match</span> <span class='ident'>pv</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>rv</span>) <span class='op'>=></span> <span class='ident'>tmp</span>.<span class='ident'>push</span>(<span class='ident'>rv</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='ident'>err</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}"</span>,<span class='ident'>pv</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>)));
|
||||
<span class='kw'>break</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='kw'>match</span> <span class='ident'>err</span> {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>e</span>) <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='ident'>e</span>),
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Ok</span>(<span class='ident'>tmp</span>)
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> <span class='prelude-val'>Err</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found"</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
<span class='doccomment'>/// Convenience macro getting a typed value `T` where `T` implements `std::fmt::FrmStr`</span>
|
||||
<span class='doccomment'>/// This macro returns a `T` or `Vec<T>` or exits with a usage string upon failure. This</span>
|
||||
<span class='doccomment'>/// removes some of the boiler plate to handle failures from value_t! above. </span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// You can use it to get a single value `T`, or a `Vec<T>` with the `values_of()`</span>
|
||||
<span class='doccomment'>/// </span>
|
||||
<span class='doccomment'>/// **NOTE:** This should only be used on required arguments, as it can be confusing to the user</span>
|
||||
<span class='doccomment'>/// why they are getting error messages when it appears they're entering all required argumetns.</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// **NOTE:** Be cautious, as since this a macro invocation it's not exactly like</span>
|
||||
<span class='doccomment'>/// standard syntax.</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// # Example single value</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// ```no_run</span>
|
||||
<span class='doccomment'>/// # #[macro_use]</span>
|
||||
<span class='doccomment'>/// # extern crate clap;</span>
|
||||
<span class='doccomment'>/// # use clap::App;</span>
|
||||
<span class='doccomment'>/// # fn main() {</span>
|
||||
<span class='doccomment'>/// let matches = App::new("myapp")</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("[length] 'Set the length to use as a positive whole number, i.e. 20'")</span>
|
||||
<span class='doccomment'>/// .get_matches();</span>
|
||||
<span class='doccomment'>/// let len = value_t_or_exit!(matches.value_of("length"), u32);</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// println!("{} + 2: {}", len, len + 2);</span>
|
||||
<span class='doccomment'>/// # }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// # Example multiple values</span>
|
||||
<span class='doccomment'>///</span>
|
||||
<span class='doccomment'>/// ```no_run</span>
|
||||
<span class='doccomment'>/// # #[macro_use]</span>
|
||||
<span class='doccomment'>/// # extern crate clap;</span>
|
||||
<span class='doccomment'>/// # use clap::App;</span>
|
||||
<span class='doccomment'>/// # fn main() {</span>
|
||||
<span class='doccomment'>/// let matches = App::new("myapp")</span>
|
||||
<span class='doccomment'>/// .arg_from_usage("[seq]... 'A sequence of positive whole numbers, i.e. 20 30 45'")</span>
|
||||
<span class='doccomment'>/// .get_matches();</span>
|
||||
<span class='doccomment'>/// for v in value_t_or_exit!(matches.values_of("seq"), u32) {</span>
|
||||
<span class='doccomment'>/// println!("{} + 2: {}", v, v + 2);</span>
|
||||
<span class='doccomment'>/// }</span>
|
||||
<span class='doccomment'>/// # }</span>
|
||||
<span class='doccomment'>/// ```</span>
|
||||
<span class='attribute'>#[<span class='ident'>macro_export</span>]</span>
|
||||
<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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>value_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>match</span> <span class='ident'>v</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>val</span>) <span class='op'>=></span> <span class='ident'>val</span>,
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}\n{}\nPlease re-run with --help for more information"</span>,<span class='ident'>v</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information"</span>,<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
};
|
||||
(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>:<span class='ident'>ident</span>.<span class='ident'>values_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> {
|
||||
<span class='kw'>match</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>values_of</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>) {
|
||||
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>v</span>) <span class='op'>=></span> {
|
||||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>tmp</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>v</span>.<span class='ident'>len</span>());
|
||||
<span class='kw'>for</span> <span class='ident'>pv</span> <span class='kw'>in</span> <span class='ident'>v</span> {
|
||||
<span class='kw'>match</span> <span class='ident'>pv</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span><span class='op'>></span>() {
|
||||
<span class='prelude-val'>Ok</span>(<span class='ident'>rv</span>) <span class='op'>=></span> <span class='ident'>tmp</span>.<span class='ident'>push</span>(<span class='ident'>rv</span>),
|
||||
<span class='prelude-val'>Err</span>(_) <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{} isn't a valid {}\n{}\nPlease re-run with --help for more information"</span>,<span class='ident'>pv</span>,<span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>t</span>), <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class='ident'>tmp</span>
|
||||
},
|
||||
<span class='prelude-val'>None</span> <span class='op'>=></span> {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information"</span>,<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>v</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>m</span>.<span class='ident'>usage</span>());
|
||||
::<span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>exit</span>(<span class='number'>1</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>
|
Loading…
Reference in a new issue