269 lines
No EOL
22 KiB
HTML
269 lines
No EOL
22 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-3765' class='srclink' href='../src/clap/args/group.rs.html#53-64' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust struct'>pub struct ArgGroup<'a> {
|
||
// some fields omitted
|
||
}</pre><div class='docblock'><p><code>ArgGroup</code>s are a family of related arguments and way for you to express, "Any of these
|
||
arguments". By placing arguments in a logical group, you can create easier requirement and
|
||
exclusion rules instead of having to list each argument individually, or when you want a rule
|
||
to apply "any but not all" arguments.</p>
|
||
|
||
<p>For instance, you can make an entire <code>ArgGroup</code> required, this means that one (and <em>only</em> one)
|
||
argument from that group must be present. Using more than one argument from an <code>ArgGroup</code>
|
||
causes a parsing failure.</p>
|
||
|
||
<p>You can also do things such as name an entire <code>ArgGroup</code> as a conflict or requirement for
|
||
another argument, 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>
|
||
|
||
<p>Finally, you may use <code>ArgGroup</code>s to pull a value from a group of arguments when you don't care
|
||
exaclty which argument was actually used at runtime.</p>
|
||
|
||
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
|
||
<p>The following example demonstrates using an <code>ArgGroup</code> to ensure that one, and only one, of
|
||
the arguments from the specified group is present at runtime.</p>
|
||
|
||
<pre class='rust rust-example-rendered'>
|
||
<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'>group</span>(<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"vers"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"set-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<'a> <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a></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: &'a <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 be used to
|
||
get values from the group or refer to the group inside of conflict and requirement rules.</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.arg' class='method'><code>fn <a href='#method.arg' class='fnname'>arg</a>(self, n: &'a <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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>arg</span>(<span class='string'>"config"</span>)</pre>
|
||
</div><h4 id='method.args' class='method'><code>fn <a href='#method.args' class='fnname'>args</a>(self, ns: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>&[</a>&'a <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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</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 group as required or not. 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>
|
||
|
||
<p><strong>NOTE:</strong> This setting only applies to the current <code>App</code> / <code>SubCommand</code>, and not globally.</p>
|
||
|
||
<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"cfg"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])
|
||
.<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: &'a <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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"other_group"</span>)
|
||
.<span class='ident'>requires</span>(<span class='string'>"files"</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>&'a <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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"other_group"</span>)
|
||
.<span class='ident'>requires_all</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>]) <span class='comment'>// No different than saying, .requires("files")</span></pre>
|
||
</div><h4 id='method.conflicts_with' class='method'><code>fn <a href='#method.conflicts_with' class='fnname'>conflicts_with</a>(self, n: &'a <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 (aka conflict) 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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"other_group"</span>)
|
||
.<span class='ident'>conflicts_with</span>(<span class='string'>"files"</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>&'a <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='kw'>let</span> <span class='ident'>cfg_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"config"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>in_arg</span> <span class='op'>=</span> <span class='ident'>Arg</span>::<span class='ident'>with_name</span>(<span class='string'>"input"</span>);
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"files"</span>)
|
||
.<span class='ident'>args</span>(<span class='kw-2'>&</span>[<span class='string'>"config"</span>, <span class='string'>"input"</span>])
|
||
<span class='comment'>// ...</span>
|
||
<span class='ident'>ArgGroup</span>::<span class='ident'>with_name</span>(<span class='string'>"other_group"</span>)
|
||
.<span class='ident'>conflicts_with_all</span>(<span class='kw-2'>&</span>[<span class='string'>"files"</span>, <span class='string'>"input"</span>]) <span class='comment'>// same as saying, conflicts_with("files")</span></pre>
|
||
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<'a> <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><'a></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#tymethod.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><h3 class='impl'><code>impl<'a, 'z> <a class='trait' href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html' title='core::convert::From'>From</a><&'z <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a>> for <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a></code></h3><div class='impl-items'><h4 id='method.from' class='method'><code>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(g: &'z <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a>) -> Self</code></h4>
|
||
</div><h3 class='impl'><code>impl<'a> <a class='trait' href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> for <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a></code></h3><div class='impl-items'><h4 id='method.clone' class='method'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> Self</code></h4>
|
||
<h4 id='method.clone_from' class='method'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code><span class="since">1.0.0</span></h4>
|
||
</div><h3 id='derived_implementations'>Derived Implementations </h3><h3 class='impl'><code>impl<'a> <a class='trait' href='https://doc.rust-lang.org/nightly/core/default/trait.Default.html' title='core::default::Default'>Default</a> for <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'a></code></h3><div class='impl-items'><h4 id='method.default' class='method'><code>fn <a href='https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> <a class='struct' href='../clap/struct.ArgGroup.html' title='clap::ArgGroup'>ArgGroup</a><'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> |