mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
289 lines
No EOL
21 KiB
HTML
289 lines
No EOL
21 KiB
HTML
<!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 `Arg` struct in crate `clap`.">
|
|
<meta name="keywords" content="rust, rustlang, rust-lang, Arg">
|
|
|
|
<title>clap::Arg - 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: 'Arg', ty: 'struct', 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 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-4820' href='../src/clap/arg.rs.html#21-53'>[src]</a></span></h1>
|
|
<pre class='rust struct'>pub struct Arg {
|
|
pub name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>,
|
|
pub short: <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a>>,
|
|
pub long: <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>,
|
|
pub help: <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>,
|
|
pub required: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>,
|
|
pub takes_value: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>,
|
|
pub index: <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>>,
|
|
pub multiple: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>,
|
|
pub blacklist: <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><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>>,
|
|
pub requires: <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><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>>,
|
|
}</pre><div class='docblock'><p>The abstract representation of a command line argument used by the consumer of the library.</p>
|
|
|
|
<p>This struct is used by the library consumer and describes the command line arguments for
|
|
their program.
|
|
and then evaluates the settings the consumer provided and determines the concret
|
|
argument struct to use when parsing.</p>
|
|
|
|
<h1 id="example" class='section-header'><a
|
|
href="#example">Example</a></h1><pre id='rust-example-rendered' class='rust '>
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"conifg"</span>)
|
|
.<span class='ident'>short</span>(<span class='string'>"c"</span>)
|
|
.<span class='ident'>long</span>(<span class='string'>"config"</span>)
|
|
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
|
.<span class='ident'>help</span>(<span class='string'>"Provides a config file to myprog"</span>)
|
|
</pre>
|
|
</div><h2 class='fields'>Fields</h2>
|
|
<table><tr><td id='structfield.name'><a class='stability Unmarked' title='No stability level'></a><code>name</code></td><td><div class='docblock'><p>The unique name of the argument, required</p>
|
|
</div></td></tr><tr><td id='structfield.short'><a class='stability Unmarked' title='No stability level'></a><code>short</code></td><td><div class='docblock'><p>The short version (i.e. single character) of the argument, no preceding <code>-</code>
|
|
<strong>NOTE:</strong> <code>short</code> is mutually exclusive with <code>index</code></p>
|
|
</div></td></tr><tr><td id='structfield.long'><a class='stability Unmarked' title='No stability level'></a><code>long</code></td><td><div class='docblock'><p>The long version of the flag (i.e. word) without the preceding <code>--</code>
|
|
<strong>NOTE:</strong> <code>long</code> is mutually exclusive with <code>index</code></p>
|
|
</div></td></tr><tr><td id='structfield.help'><a class='stability Unmarked' title='No stability level'></a><code>help</code></td><td><div class='docblock'><p>The string of text that will displayed to the user when the application's
|
|
<code>help</code> text is displayed</p>
|
|
</div></td></tr><tr><td id='structfield.required'><a class='stability Unmarked' title='No stability level'></a><code>required</code></td><td><div class='docblock'><p>If this is a required by default when using the command line program
|
|
i.e. a configuration file that's required for the program to function
|
|
<strong>NOTE:</strong> required by default means, it is required <em>until</em> mutually
|
|
exclusive arguments are evaluated.</p>
|
|
</div></td></tr><tr><td id='structfield.takes_value'><a class='stability Unmarked' title='No stability level'></a><code>takes_value</code></td><td><div class='docblock'><p>Determines if this argument is an option, vice a flag or positional and
|
|
is mutually exclusive with <code>index</code> and <code>multiple</code></p>
|
|
</div></td></tr><tr><td id='structfield.index'><a class='stability Unmarked' title='No stability level'></a><code>index</code></td><td><div class='docblock'><p>The index of the argument. <code>index</code> is mutually exclusive with <code>takes_value</code>
|
|
and <code>multiple</code></p>
|
|
</div></td></tr><tr><td id='structfield.multiple'><a class='stability Unmarked' title='No stability level'></a><code>multiple</code></td><td><div class='docblock'><p>Determines if multiple instances of the same flag are allowed. <code>multiple</code>
|
|
is mutually exclusive with <code>index</code> and <code>takes_value</code>.
|
|
I.e. <code>-v -v -v</code> or <code>-vvv</code></p>
|
|
</div></td></tr><tr><td id='structfield.blacklist'><a class='stability Unmarked' title='No stability level'></a><code>blacklist</code></td><td><div class='docblock'><p>A list of names for other arguments that <em>may not</em> be used with this flag</p>
|
|
</div></td></tr><tr><td id='structfield.requires'><a class='stability Unmarked' title='No stability level'></a><code>requires</code></td><td><div class='docblock'><p>A list of names of other arguments that are <em>required</em> to be used when
|
|
this flag is used</p>
|
|
</div></td></tr></table><h2 id='methods'>Methods</h2><h3 class='impl'><a class='stability Unmarked' title='No stability level'></a><code>impl <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h3><div class='impl-items'><h4 id='method.new' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.new' class='fnname'>new</a>(n: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Creates a new instace of <code>Arg</code> using a unique string name.
|
|
The name will be used by the library consumer to get information about
|
|
whether or not the argument was used at runtime. </p>
|
|
|
|
<p><strong>NOTE:</strong> in the case of arguments that take values (i.e. <code>takes_value(true)</code>)
|
|
and positional arguments (i.e. those without a <code>-</code> or <code>--</code>) the name will also
|
|
be displayed when the user prints the usage/help information of the program.</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
<span class='ident'>Arg</span>::<span class='ident'>new</span>(<span class='string'>"conifg"</span>)
|
|
</pre>
|
|
</div><h4 id='method.short' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.short' class='fnname'>short</a>(self, s: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets the short version of the argument without the preceding <code>-</code>.</p>
|
|
|
|
<p>By default <code>clap</code> automatically assigns <code>v</code> and <code>h</code> to display version and help information
|
|
respectivly. You may use <code>v</code> or <code>h</code> for your own purposes, in which case <code>clap</code> simply
|
|
will not asign those to the displaying of version or help.</p>
|
|
|
|
<p><strong>NOTE:</strong> Any leading <code>-</code> characters will be stripped, and only the first
|
|
non <code>-</code> chacter will be used as the <code>short</code> version, i.e. for when the user
|
|
mistakenly sets the short to <code>-o</code> or the like.
|
|
Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>short</span>(<span class='string'>"c"</span>)
|
|
</pre>
|
|
</div><h4 id='method.long' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.long' class='fnname'>long</a>(self, l: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets the long version of the argument without the preceding <code>--</code>.</p>
|
|
|
|
<p>By default <code>clap</code> automatically assigns <code>version</code> and <code>help</code> to display version and help information
|
|
respectivly. You may use <code>version</code> or <code>help</code> for your own purposes, in which case <code>clap</code> simply
|
|
will not asign those to the displaying of version or help automatically, and you will have to do
|
|
so manually.</p>
|
|
|
|
<p><strong>NOTE:</strong> Any leading <code>-</code> characters will be stripped i.e. for
|
|
when the user mistakenly sets the short to <code>--out</code> or the like.</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>long</span>(<span class='string'>"config"</span>)
|
|
</pre>
|
|
</div><h4 id='method.help' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.help' class='fnname'>help</a>(self, h: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets the help text of the argument that will be displayed to the user
|
|
when they print the usage/help information. </p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>help</span>(<span class='string'>"The config file used by the myprog"</span>)
|
|
</pre>
|
|
</div><h4 id='method.required' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.required' class='fnname'>required</a>(self, r: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets whether or not the argument is required by default. Required by
|
|
default means it is required, when no other mutually exlusive rules have
|
|
been evaluated. Mutually exclusive rules take precedence over being required
|
|
by default.</p>
|
|
|
|
<p><strong>NOTE:</strong> Flags (i.e. not positional, or arguments that take values)
|
|
cannot be required by default.
|
|
when they print the usage/help information. </p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>required</span>(<span class='boolval'>true</span>)
|
|
</pre>
|
|
</div><h4 id='method.mutually_excludes' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes' class='fnname'>mutually_excludes</a>(self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets a mutually exclusive argument by name. I.e. when using this argument,
|
|
the following argument can't be present.</p>
|
|
|
|
<p><strong>NOTE:</strong> Mutually exclusive rules take precedence over being required
|
|
by default. Mutually exclusive rules only need to be set for one of the two
|
|
arguments, they do not need to be set for each.</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>mutually_excludes</span>(<span class='string'>"debug"</span>)
|
|
</pre>
|
|
</div><h4 id='method.mutually_excludes_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.mutually_excludes_all' class='fnname'>mutually_excludes_all</a>(self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets a mutually exclusive arguments by names. I.e. when using this argument,
|
|
the following argument can't be present.</p>
|
|
|
|
<p><strong>NOTE:</strong> Mutually exclusive rules take precedence over being required
|
|
by default. Mutually exclusive rules only need to be set for one of the two
|
|
arguments, they do not need to be set for each.</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>mutually_excludes_all</span>(
|
|
<span class='macro'>vec</span><span class='macro'>!</span>[<span class='string'>"debug"</span>, <span class='string'>"input"</span>])
|
|
</pre>
|
|
</div><h4 id='method.requires' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires' class='fnname'>requires</a>(self, name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets an argument by name that is required when this one is presnet I.e. when
|
|
using this argument, the following argument <em>must</em> be present.</p>
|
|
|
|
<p><strong>NOTE:</strong> Mutually exclusive rules take precedence over being required</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>requires</span>(<span class='string'>"debug"</span>)
|
|
</pre>
|
|
</div><h4 id='method.requires_all' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.requires_all' class='fnname'>requires_all</a>(self, names: <a class='struct' href='http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Sets arguments by names that are required when this one is presnet I.e. when
|
|
using this argument, the following arguments <em>must</em> be present.</p>
|
|
|
|
<p><strong>NOTE:</strong> Mutually exclusive rules take precedence over being required
|
|
by default. </p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>requires_all</span>(
|
|
<span class='macro'>vec</span><span class='macro'>!</span>[<span class='string'>"debug"</span>, <span class='string'>"input"</span>])
|
|
</pre>
|
|
</div><h4 id='method.takes_value' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.takes_value' class='fnname'>takes_value</a>(self, tv: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Specifies that the argument takes an additional value at run time.</p>
|
|
|
|
<p><strong>NOTE:</strong> When setting this to <code>true</code> the <code>name</code> of the argument
|
|
will be used when printing the help/usage information to the user. </p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>takes_value</span>(<span class='boolval'>true</span>)
|
|
</pre>
|
|
</div><h4 id='method.index' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.index' class='fnname'>index</a>(self, idx: <a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Specifies the index of a positional argument starting at 1.</p>
|
|
|
|
<p><strong>NOTE:</strong> When setting this, any <code>short</code> or <code>long</code> values you set
|
|
are ignored as positional arguments cannot have a <code>short</code> or <code>long</code>.
|
|
Also, the name will be used when printing the help/usage information
|
|
to the user. </p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>index</span>(<span class='number'>1</span>)
|
|
</pre>
|
|
</div><h4 id='method.multiple' class='method'><a class='stability Unmarked' title='No stability level'></a><code>fn <a href='#method.multiple' class='fnname'>multiple</a>(self, multi: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='../clap/struct.Arg.html' title='clap::Arg'>Arg</a></code></h4>
|
|
<div class='docblock'><p>Specifies if the flag may appear more than once such as for multiple debugging
|
|
levels (as an example). <code>-ddd</code> for three levels of debugging, or <code>-d -d -d</code>.
|
|
When this is set to <code>true</code> you recieve the number of occurances the user supplied
|
|
of a particular flag at runtime.</p>
|
|
|
|
<p><strong>NOTE:</strong> When setting this, any <code>takes_value</code> or <code>index</code> values you set
|
|
are ignored as flags cannot have a values or an <code>index</code>.</p>
|
|
|
|
<p>Example:</p>
|
|
<pre id='rust-example-rendered' class='rust '>
|
|
.<span class='ident'>multiple</span>(<span class='boolval'>true</span>)
|
|
</pre>
|
|
</div></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> |