mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
updated docs
This commit is contained in:
parent
1c752d38d1
commit
3c0b050a26
9 changed files with 69 additions and 29 deletions
10
README.md
10
README.md
|
@ -69,15 +69,15 @@ Command Line Argument Parser written in Rust
|
|||
MyApp [FLAGS] [OPTIONS] [POSITIONAL]
|
||||
|
||||
FLAGS:
|
||||
-d Turn debugging information on
|
||||
-h,--help Prints this message
|
||||
-v,--version Prints version information
|
||||
-d Turn debugging information on
|
||||
-h,--help Prints this message
|
||||
-v,--version Prints version information
|
||||
|
||||
OPTIONS:
|
||||
-c,--config <config> Sets a custom config file
|
||||
-c,--config <config> Sets a custom config file
|
||||
|
||||
POSITIONAL ARGUMENTS:
|
||||
output Sets an optional output file
|
||||
output Sets an optional output file
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
|
|
@ -109,15 +109,15 @@
|
|||
MyApp [FLAGS] [OPTIONS] [POSITIONAL]
|
||||
|
||||
FLAGS:
|
||||
-d Turn debugging information on
|
||||
-h,--help Prints this message
|
||||
-v,--version Prints version information
|
||||
d--help Turn debugging information on
|
||||
h--version,--help Prints this message
|
||||
vd--help,--version Prints version information
|
||||
|
||||
OPTIONS:
|
||||
-c,--config <config> Sets a custom config file
|
||||
ch--version,--config <config> Sets a custom config file
|
||||
|
||||
POSITIONAL ARGUMENTS:
|
||||
output Sets an optional output file
|
||||
output Sets an optional output file
|
||||
</code></pre>
|
||||
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||||
<table>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<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=''>App</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-19' href='../src/clap/app.rs.html#35-55'>[src]</a></span></h1>
|
||||
</span><a id='src-19' href='../src/clap/app.rs.html#35-57'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct App {
|
||||
pub name: &'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>,
|
||||
pub author: <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>>,
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<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-4288' href='../src/clap/arg.rs.html#20-52'>[src]</a></span></h1>
|
||||
</span><a id='src-4455' href='../src/clap/arg.rs.html#20-52'>[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>>,
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<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=''>ArgMatches</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-4078' href='../src/clap/argmatches.rs.html#48-58'>[src]</a></span></h1>
|
||||
</span><a id='src-4245' href='../src/clap/argmatches.rs.html#48-58'>[src]</a></span></h1>
|
||||
<pre class='rust struct'>pub struct ArgMatches {
|
||||
pub required: <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 blacklist: <a class='struct' href='http://doc.rust-lang.org/nightly/std/collections/hash/set/struct.HashSet.html' title='std::collections::hash::set::HashSet'>HashSet</a><&'static <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>>,
|
||||
|
|
|
@ -717,6 +717,26 @@
|
|||
<span id="675">675</span>
|
||||
<span id="676">676</span>
|
||||
<span id="677">677</span>
|
||||
<span id="678">678</span>
|
||||
<span id="679">679</span>
|
||||
<span id="680">680</span>
|
||||
<span id="681">681</span>
|
||||
<span id="682">682</span>
|
||||
<span id="683">683</span>
|
||||
<span id="684">684</span>
|
||||
<span id="685">685</span>
|
||||
<span id="686">686</span>
|
||||
<span id="687">687</span>
|
||||
<span id="688">688</span>
|
||||
<span id="689">689</span>
|
||||
<span id="690">690</span>
|
||||
<span id="691">691</span>
|
||||
<span id="692">692</span>
|
||||
<span id="693">693</span>
|
||||
<span id="694">694</span>
|
||||
<span id="695">695</span>
|
||||
<span id="696">696</span>
|
||||
<span id="697">697</span>
|
||||
</pre><pre class='rust '>
|
||||
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
|
||||
|
||||
|
@ -771,6 +791,8 @@
|
|||
<span class='ident'>needs_short_version</span>: <span class='ident'>bool</span>,
|
||||
<span class='ident'>required</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
||||
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
||||
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='ident'>char</span><span class='op'>></span>,
|
||||
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span><span class='op'>></span>,
|
||||
}
|
||||
|
||||
|
@ -799,6 +821,8 @@
|
|||
<span class='ident'>needs_short_version</span>: <span class='boolval'>true</span>,
|
||||
<span class='ident'>required</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
||||
<span class='ident'>blacklist</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
||||
}
|
||||
}
|
||||
|
@ -851,6 +875,22 @@
|
|||
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>arg</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>a</span>: <span class='kw-2'>&</span><span class='ident'>Arg</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>App</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>arg_list</span>.<span class='ident'>contains</span>(<span class='ident'>a</span>.<span class='ident'>name</span>) {
|
||||
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument name must be unique, \"{}\" is already in use"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>arg_list</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</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'>s</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>short</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>short_list</span>.<span class='ident'>contains</span>(<span class='ident'>s</span>) {
|
||||
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument short must be unique, -{} is already in use"</span>, <span class='ident'>s</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>short_list</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>s</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'>l</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>long</span> {
|
||||
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>long_list</span>.<span class='ident'>contains</span>(<span class='ident'>l</span>) {
|
||||
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument long must be unique, --{} is already in use"</span>, <span class='ident'>l</span>);
|
||||
} <span class='kw'>else</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>long_list</span>.<span class='ident'>insert</span>(<span class='ident'>l</span>);
|
||||
}
|
||||
}
|
||||
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>required</span> {
|
||||
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>a</span>.<span class='ident'>name</span>);
|
||||
|
@ -974,7 +1014,7 @@
|
|||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"FLAGS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>iter</span>() {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}\t{}"</span>,
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}\t{}"</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'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</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'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" \t"</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'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
|
@ -984,7 +1024,7 @@
|
|||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"OPTIONS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>iter</span>() {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}\t\t{}"</span>,
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}{}\t\t{}"</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'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</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'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" "</span>)},
|
||||
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" <{}>"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>),
|
||||
|
@ -995,7 +1035,7 @@
|
|||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"POSITIONAL ARGUMENTS:"</span>);
|
||||
<span class='kw'>for</span> (_, <span class='ident'>v</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>iter</span>() {
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}\t\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>,
|
||||
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}\t\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</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'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {<span class='op'>*</span><span class='ident'>h</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,15 +204,15 @@
|
|||
<span class='doccomment'>//! MyApp [FLAGS] [OPTIONS] [POSITIONAL]</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
<span class='doccomment'>//! FLAGS:</span>
|
||||
<span class='doccomment'>//! -d Turn debugging information on</span>
|
||||
<span class='doccomment'>//! -h,--help Prints this message</span>
|
||||
<span class='doccomment'>//! -v,--version Prints version information</span>
|
||||
<span class='doccomment'>//! d--help Turn debugging information on</span>
|
||||
<span class='doccomment'>//! h--version,--help Prints this message</span>
|
||||
<span class='doccomment'>//! vd--help,--version Prints version information</span>
|
||||
<span class='doccomment'>//! </span>
|
||||
<span class='doccomment'>//! OPTIONS:</span>
|
||||
<span class='doccomment'>//! -c,--config <config> Sets a custom config file</span>
|
||||
<span class='doccomment'>//! ch--version,--config <config> Sets a custom config file</span>
|
||||
<span class='doccomment'>//!</span>
|
||||
<span class='doccomment'>//! POSITIONAL ARGUMENTS:</span>
|
||||
<span class='doccomment'>//! output Sets an optional output file</span>
|
||||
<span class='doccomment'>//! output Sets an optional output file</span>
|
||||
<span class='doccomment'>//! ```</span>
|
||||
|
||||
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='ident'>argmatches</span>::<span class='ident'>ArgMatches</span>;
|
||||
|
|
|
@ -274,7 +274,7 @@ impl App {
|
|||
println!("");
|
||||
println!("FLAGS:");
|
||||
for (_, v) in self.flags.iter() {
|
||||
println!("{}{}\t{}",
|
||||
println!("\t{}{}\t{}",
|
||||
if let Some(ref s) = v.short{format!("-{}",s)}else{format!(" ")},
|
||||
if let Some(ref l) = v.long {format!(",--{}",l)}else {format!(" \t")},
|
||||
if let Some(ref h) = v.help {*h} else {" "} );
|
||||
|
@ -284,7 +284,7 @@ impl App {
|
|||
println!("");
|
||||
println!("OPTIONS:");
|
||||
for (_, v) in self.opts.iter() {
|
||||
println!("{}{}{}\t\t{}",
|
||||
println!("\t{}{}{}\t\t{}",
|
||||
if let Some(ref s) = v.short{format!("-{}",s)}else{format!(" ")},
|
||||
if let Some(ref l) = v.long {format!(",--{}",l)}else {format!(" ")},
|
||||
format!(" <{}>", v.name),
|
||||
|
@ -295,7 +295,7 @@ impl App {
|
|||
println!("");
|
||||
println!("POSITIONAL ARGUMENTS:");
|
||||
for (_, v) in self.positionals_idx.iter() {
|
||||
println!("{}\t\t\t{}", v.name,
|
||||
println!("\t{}\t\t\t{}", v.name,
|
||||
if let Some(ref h) = v.help {*h} else {" "} );
|
||||
}
|
||||
}
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -70,15 +70,15 @@
|
|||
//! MyApp [FLAGS] [OPTIONS] [POSITIONAL]
|
||||
//!
|
||||
//! FLAGS:
|
||||
//! -d Turn debugging information on
|
||||
//! -h,--help Prints this message
|
||||
//! -v,--version Prints version information
|
||||
//! d--help Turn debugging information on
|
||||
//! h--version,--help Prints this message
|
||||
//! vd--help,--version Prints version information
|
||||
//!
|
||||
//! OPTIONS:
|
||||
//! -c,--config <config> Sets a custom config file
|
||||
//! ch--version,--config <config> Sets a custom config file
|
||||
//!
|
||||
//! POSITIONAL ARGUMENTS:
|
||||
//! output Sets an optional output file
|
||||
//! output Sets an optional output file
|
||||
//! ```
|
||||
|
||||
pub use argmatches::ArgMatches;
|
||||
|
|
Loading…
Reference in a new issue