215 lines
No EOL
14 KiB
HTML
215 lines
No EOL
14 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 `ArgGroup` struct in crate `clap`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, ArgGroup">
|
||
|
||
<title>clap::ArgGroup - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
|
||
<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]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
|
||
<p class='location'><a href='index.html'>clap</a></p><script>window.sidebarCurrent = {name: 'ArgGroup', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
|
||
</nav>
|
||
|
||
<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=''>ArgGroup</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a id='src-3865' class='srclink' href='../src/clap/args/group.rs.html.html#44-55' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust struct'>pub struct ArgGroup<'n, 'ar> {
|
||
// some fields omitted
|
||
}</pre><div class='docblock'><p><code>ArgGroup</code>s are a family of related arguments and way for you to say, "Any of these arguments".
|
||
By placing arguments in a logical group, you can make easier requirement and exclusion rules
|
||
instead of having to list each individually, or when you want a rule to apply "any but not all"
|
||
arguments.</p>
|
||
|
||
<p>For instance, you can make an entire ArgGroup required, this means that one (and <em>only</em> one)
|
||
argument. from that group must be present. Using more than one argument from an ArgGroup causes
|
||
a failure (graceful exit).</p>
|
||
|
||
<p>You can also do things such as name an ArgGroup as a confliction or requirement, meaning any
|
||
of the arguments that belong to that group will cause a failure if present, or must present
|
||
respectively.</p>
|
||
|
||
<p>Perhaps the most common use of <code>ArgGroup</code>s is to require one and <em>only</em> one argument to be
|
||
present out of a given set. Imagine that you had multiple arguments, and you want one of them
|
||
to be required, but making all of them required isn't feasible because perhaps they conflict
|
||
with each other. For example, lets say that you were building an application where one could
|
||
set a given version number by supplying a string with an option argument, i.e.
|
||
<code>--set-ver v1.2.3</code>, you also wanted to support automatically using a previous version number
|
||
and simply incrementing one of the three numbers. So you create three flags <code>--major</code>,
|
||
<code>--minor</code>, and <code>--patch</code>. All of these arguments shouldn't be used at one time but you want to
|
||
specify that <em>at least one</em> of them is used. For this, you can create a group.</p>
|
||
|
||
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>let</span> _ <span class='op'>=</span> <span class='ident'>App</span>::<span class='ident'>new</span>(<span class='string'>"app"</span>)
|
||
.<span class='ident'>args_from_usage</span>(<span class='string'>"--set-ver [ver] 'set the version manually'
|
||
--major 'auto increase major'
|
||
--minor 'auto increase minor'
|
||
--patch 'auto increase patch"</span>)
|
||
.<span class='ident'>arg_group</span>(<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"vers"</span>)
|
||
.<span class='ident'>add_all</span>(<span class='kw-2'>&</span>[<span class='string'>"ver"</span>, <span class='string'>"major"</span>, <span class='string'>"minor"</span>,<span class='string'>"patch"</span>])
|
||
.<span class='ident'>required</span>(<span class='boolval'>true</span>))</pre>
|
||
</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl<'n, 'ar> <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'n, 'ar></code></h3><div class='impl-items'><h4 id='method.with_name' class='method'><code>fn <a href='#method.with_name' class='fnname'>with_name</a>(n: &'n <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Creates a new instance of <code>ArgGroup</code> using a unique string name.
|
||
The name will only be used by the library consumer and not displayed to the use.</p>
|
||
|
||
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>)</pre>
|
||
</div><h4 id='method.add' class='method'><code>fn <a href='#method.add' class='fnname'>add</a>(self, n: &'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Adds an argument to this group by name</p>
|
||
|
||
<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>add</span>(<span class='string'>"config"</span>)</pre>
|
||
</div><h4 id='method.add_all' class='method'><code>fn <a href='#method.add_all' class='fnname'>add_all</a>(self, ns: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>&[</a>&'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a><a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>]</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Adds multiple arguments to this group by name</p>
|
||
|
||
<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>add_all</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>, <span class='string'>"output"</span>])</pre>
|
||
</div><h4 id='method.required' class='method'><code>fn <a href='#method.required' class='fnname'>required</a>(self, r: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Sets the requirement of this group. A required group will be displayed in the usage string
|
||
of the application in the format <code>[arg|arg2|arg3]</code>. A required <code>ArgGroup</code> simply states
|
||
that one, and only one argument from this group <em>must</em> be present at runtime (unless
|
||
conflicting with another argument).</p>
|
||
|
||
<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>required</span>(<span class='boolval'>true</span>)</pre>
|
||
</div><h4 id='method.requires' class='method'><code>fn <a href='#method.requires' class='fnname'>requires</a>(self, n: &'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Sets the requirement rules of this group. This is not to be confused with a required group.
|
||
Requirement rules function just like argument requirement rules, you can name other
|
||
arguments or groups that must be present when one of the arguments from this group is used.</p>
|
||
|
||
<p><strong>NOTE:</strong> The name provided may be an argument, or group name</p>
|
||
|
||
<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>requires</span>(<span class='string'>"config"</span>)</pre>
|
||
</div><h4 id='method.requires_all' class='method'><code>fn <a href='#method.requires_all' class='fnname'>requires_all</a>(self, ns: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>&[</a>&'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a><a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>]</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Sets the requirement rules of this group. This is not to be confused with a required group.
|
||
Requirement rules function just like argument requirement rules, you can name other
|
||
arguments or groups that must be present when one of the arguments from this group is used.</p>
|
||
|
||
<p><strong>NOTE:</strong> The names provided may be an argument, or group name</p>
|
||
|
||
<h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>requires_all</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])</pre>
|
||
</div><h4 id='method.conflicts_with' class='method'><code>fn <a href='#method.conflicts_with' class='fnname'>conflicts_with</a>(self, n: &'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Sets the exclusion rules of this group. Exclusion rules function just like argument
|
||
exclusion rules, you can name other arguments or groups that must not be present when one
|
||
of the arguments from this group are used.</p>
|
||
|
||
<p><strong>NOTE:</strong> The name provided may be an argument, or group name</p>
|
||
|
||
<h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>conflicts_with</span>(<span class='string'>"config"</span>)</pre>
|
||
</div><h4 id='method.conflicts_with_all' class='method'><code>fn <a href='#method.conflicts_with_all' class='fnname'>conflicts_with_all</a>(self, ns: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>&[</a>&'ar <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a><a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>]</a>) -> Self</code></h4>
|
||
<div class='docblock'><p>Sets the exclusion rules of this group. Exclusion rules function just like argument
|
||
exclusion rules, you can name other arguments or groups that must not be present when one
|
||
of the arguments from this group are used.</p>
|
||
|
||
<p><strong>NOTE:</strong> The names provided may be an argument, or group name</p>
|
||
|
||
<h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
.<span class='ident'>conflicts_with_all</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])</pre>
|
||
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<'n, 'ar> <a class='trait' href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html' title='core::fmt::Debug'>Debug</a> for <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'n, 'ar></code></h3><div class='impl-items'><h4 id='method.fmt' class='method'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#method.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class='struct' href='https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title='core::fmt::Formatter'>Formatter</a>) -> <a class='type' href='https://doc.rust-lang.org/nightly/core/fmt/type.Result.html' title='core::fmt::Result'>Result</a></code></h4>
|
||
</div></section>
|
||
<section id='search' class="content hidden"></section>
|
||
|
||
<section class="footer"></section>
|
||
|
||
<aside id="help" class="hidden">
|
||
<div>
|
||
<h1 class="hidden">Help</h1>
|
||
|
||
<div class="shortcuts">
|
||
<h2>Keyboard Shortcuts</h2>
|
||
|
||
<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">
|
||
<h2>Search Tricks</h2>
|
||
|
||
<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>type</code>, <code>macro</code>,
|
||
and <code>const</code>.
|
||
</p>
|
||
|
||
<p>
|
||
Search functions by type signature (e.g.
|
||
<code>vec -> usize</code> or <code>* -> vec</code>)
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../";
|
||
window.currentCrate = "clap";
|
||
window.playgroundUrl = "";
|
||
</script>
|
||
<script src="../jquery.js"></script>
|
||
<script src="../main.js"></script>
|
||
|
||
<script defer src="../search-index.js"></script>
|
||
</body>
|
||
</html> |