ssw/doc/clap/macro.arg.html
2023-01-09 19:23:20 +01:00

65 lines
10 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Create an `Arg` from a usage string."><meta name="keywords" content="rust, rustlang, rust-lang, arg"><title>arg in clap - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../clap/index.html"><div class="logo-container"><img src="https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../clap/index.html"><div class="logo-container">
<img src="https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png" alt="logo"></div></a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In clap</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../clap/index.html">
<img src="https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn"><span class="in-band">Macro <a href="index.html">clap</a>::<wbr><a class="macro" href="#">arg</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/clap/macros.rs.html#538-551">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">arg</span> {
( <span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span>:<span class="ident">ident</span>: $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tail</span>:<span class="ident">tt</span>)<span class="op">+</span> ) =&gt; { ... };
( $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tail</span>:<span class="ident">tt</span>)<span class="op">+</span> ) =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Create an <a href="builder/struct.Arg.html"><code>Arg</code></a> from a usage string.</p>
<p>Allows creation of basic settings for the <a href="builder/struct.Arg.html"><code>Arg</code></a>.</p>
<p><strong>NOTE</strong>: Not all settings may be set using the usage string method. Some properties are
only available via the builder pattern.</p>
<h2 id="syntax"><a href="#syntax">Syntax</a></h2>
<p>Usage strings typically following the form:</p>
<div class="example-wrap"><pre class="language-notrust"><code>[explicit name] [short] [long] [value names] [...] [help string]</code></pre></div><h4 id="explicit-name"><a href="#explicit-name">Explicit Name</a></h4>
<p>The name may be either a bare-word or a string, followed by a <code>:</code>, like <code>name:</code> or
<code>&quot;name&quot;:</code>.</p>
<p><em>Note:</em> This is an optional field, if its omitted the argument will use one of the additional
fields as the name using the following priority order:</p>
<ol>
<li>Explicit Name</li>
<li>Long</li>
<li>Value Name</li>
</ol>
<p>See <a href="builder/struct.Arg.html#method.id" title="crate::Arg::id"><code>Arg::id</code></a>.</p>
<h4 id="short"><a href="#short">Short</a></h4>
<p>A short flag is a <code>-</code> followed by either a bare-character or quoted character, like <code>-f</code> or
<code>-'f'</code>.</p>
<p>See <a href="builder/struct.Arg.html#method.short" title="crate::Arg::short"><code>Arg::short</code></a>.</p>
<h4 id="long"><a href="#long">Long</a></h4>
<p>A long flag is a <code>--</code> followed by either a bare-word or a string, like <code>--foo</code> or
<code>--&quot;foo&quot;</code>.</p>
<p><strong>NOTE:</strong> Dashes in the long name (e.g. <code>--foo-bar</code>) is not supported and quoting is required
(e.g. <code>--&quot;foo-bar&quot;</code>).</p>
<p>See <a href="builder/struct.Arg.html#method.long" title="crate::Arg::long"><code>Arg::long</code></a>.</p>
<h4 id="values-value-notation"><a href="#values-value-notation">Values (Value Notation)</a></h4>
<p>This is set by placing bare-word between:</p>
<ul>
<li><code>[]</code> like <code>[FOO]</code>
<ul>
<li>Positional argument: optional</li>
<li>Named argument: optional value</li>
</ul>
</li>
<li><code>&lt;&gt;</code> like <code>&lt;FOO&gt;</code>: required</li>
</ul>
<p>See <a href="builder/struct.Arg.html#method.value_name" title="crate::Arg::value_name"><code>Arg::value_name</code></a>.</p>
<h4 id=""><a href="#"><code>...</code></a></h4>
<p><code>...</code> (three consecutive dots/periods) specifies that this argument may occur multiple
times (not to be confused with multiple values per occurrence).</p>
<p>See <a href="builder/enum.ArgAction.html#variant.Count" title="crate::ArgAction::Count"><code>ArgAction::Count</code></a> and <a href="builder/enum.ArgAction.html#variant.Append" title="crate::ArgAction::Append"><code>ArgAction::Append</code></a>.</p>
<h4 id="help-string"><a href="#help-string">Help String</a></h4>
<p>The help string is denoted between a pair of double quotes <code>&quot;&quot;</code> and may contain any
characters.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">cmd</span> <span class="op">=</span> <span class="ident">Command::new</span>(<span class="string">&quot;prog&quot;</span>)
.<span class="ident">args</span>(<span class="kw-2">&amp;</span>[
<span class="macro">arg!</span>(<span class="op">-</span><span class="op">-</span><span class="ident">config</span> <span class="op">&lt;</span><span class="ident">FILE</span><span class="op">&gt;</span> <span class="string">&quot;a required file for the configuration and no short&quot;</span>),
<span class="macro">arg!</span>(<span class="op">-</span><span class="ident">d</span> <span class="op">-</span><span class="op">-</span><span class="ident">debug</span> ... <span class="string">&quot;turns on debugging information and allows multiples&quot;</span>),
<span class="macro">arg!</span>([<span class="ident">input</span>] <span class="string">&quot;an optional input file to use&quot;</span>)
]);
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="ident">cmd</span>.<span class="ident">try_get_matches_from</span>([<span class="string">&quot;prog&quot;</span>, <span class="string">&quot;--config&quot;</span>, <span class="string">&quot;file.toml&quot;</span>]).<span class="ident">unwrap</span>();
<span class="macro">assert_eq!</span>(<span class="ident">m</span>.<span class="ident">get_one</span>::<span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>(<span class="string">&quot;config&quot;</span>).<span class="ident">unwrap</span>(), <span class="string">&quot;file.toml&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span><span class="ident">m</span>.<span class="ident">get_one</span>::<span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span>(<span class="string">&quot;debug&quot;</span>).<span class="ident">unwrap</span>(), <span class="number">0</span>);
<span class="macro">assert_eq!</span>(<span class="ident">m</span>.<span class="ident">get_one</span>::<span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>(<span class="string">&quot;input&quot;</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="clap" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.64.0 (a55dd71d5 2022-09-19)" ></div></body></html>