Struct sarge::ArgumentReader
source · pub struct ArgumentReader {
pub doc: Option<String>,
/* private fields */
}Expand description
The structure that actually reads all your arguments.
Use ArgumentReader::add to register arguments and get ArgumentRefs.
Then, use ArgumentReader::parse{_cli,_env,_provided} to get
Arguments, which contains the results of parsing. Finally, you can use
ArgumentRef::get to retrieve the values of your arguments.
Fields§
§doc: Option<String>Program-level documentation.
Only available on feature help.
Implementations§
source§impl ArgumentReader
impl ArgumentReader
sourcepub fn new() -> Self
pub fn new() -> Self
Returns an empty ArgumentReader.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let mut parser = ArgumentReader::new();
parser.doc = Some("An example demonstrating automatic documentation generation.".into());
parser.add::<bool>(tag::both('a', "abc").env("ABC").doc("Super duper docs"));
parser.add::<bool>(tag::short('b').env("BAR"));
parser.add::<String>(tag::long("baz-arg"));
parser.add::<u32>(tag::both('f', "foo").doc("Hello, World!"));
parser.add::<bool>(tag::short('x').doc("Testing testing 123"));
parser.add::<bool>(tag::long("xy").doc("Testing testing 456"));
parser.add::<Vec<i8>>(tag::env("ENV_ONLY").doc(
"This is really, really long, multiline argument\ndocumentation, it'll wrap nicely I hope",
));
parser.print_help();
}sourcepub fn print_help(&self)
pub fn print_help(&self)
Prints help for all the arguments.
Only available on feature help.
§Panics
If the name of the executable could not be found, panics.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let mut parser = ArgumentReader::new();
parser.doc = Some("An example demonstrating automatic documentation generation.".into());
parser.add::<bool>(tag::both('a', "abc").env("ABC").doc("Super duper docs"));
parser.add::<bool>(tag::short('b').env("BAR"));
parser.add::<String>(tag::long("baz-arg"));
parser.add::<u32>(tag::both('f', "foo").doc("Hello, World!"));
parser.add::<bool>(tag::short('x').doc("Testing testing 123"));
parser.add::<bool>(tag::long("xy").doc("Testing testing 456"));
parser.add::<Vec<i8>>(tag::env("ENV_ONLY").doc(
"This is really, really long, multiline argument\ndocumentation, it'll wrap nicely I hope",
));
parser.print_help();
}sourcepub fn add<T: ArgumentType>(&mut self, tag: Full) -> ArgumentRef<T>
pub fn add<T: ArgumentType>(&mut self, tag: Full) -> ArgumentRef<T>
Adds an argument to the parser.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let mut parser = ArgumentReader::new();
parser.doc = Some("An example demonstrating automatic documentation generation.".into());
parser.add::<bool>(tag::both('a', "abc").env("ABC").doc("Super duper docs"));
parser.add::<bool>(tag::short('b').env("BAR"));
parser.add::<String>(tag::long("baz-arg"));
parser.add::<u32>(tag::both('f', "foo").doc("Hello, World!"));
parser.add::<bool>(tag::short('x').doc("Testing testing 123"));
parser.add::<bool>(tag::long("xy").doc("Testing testing 456"));
parser.add::<Vec<i8>>(tag::env("ENV_ONLY").doc(
"This is really, really long, multiline argument\ndocumentation, it'll wrap nicely I hope",
));
parser.print_help();
}sourcepub fn parse(self) -> Result<Arguments, ArgParseError>
pub fn parse(self) -> Result<Arguments, ArgParseError>
Parse arguments from std::env::{args,vars}.
§Errors
If any arguments fail to parse their values, this
will forward that error. Otherwise, see
ArgParseError for a list of all possible errors.
sourcepub fn parse_provided<A: AsRef<str>, IA: IntoIterator<Item = A>, K: AsRef<str>, V: AsRef<str>, IE: IntoIterator<Item = (K, V)>>(
self,
cli: IA,
env: IE
) -> Result<Arguments, ArgParseError>
pub fn parse_provided<A: AsRef<str>, IA: IntoIterator<Item = A>, K: AsRef<str>, V: AsRef<str>, IE: IntoIterator<Item = (K, V)>>( self, cli: IA, env: IE ) -> Result<Arguments, ArgParseError>
Parse from the provided environment variables and CLI arguments.
§Errors
If any arguments fail to parse their values, this
will forward that error. Otherwise, see
ArgParseError for a list of all possible errors.
Trait Implementations§
source§impl Clone for ArgumentReader
impl Clone for ArgumentReader
source§fn clone(&self) -> ArgumentReader
fn clone(&self) -> ArgumentReader
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more