pub struct Clappers { /* private fields */ }Implementations
sourceimpl Clappers
impl Clappers
sourcepub fn build() -> Self
pub fn build() -> Self
Build a Clappers parser
Parameters
None.
Return value
An empty Clappers parser, which is ready to be configured by chaining:
set_flags()set_singles()set_multiples()
Once configured, parse() is chained last to parse the actual command line arguments
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help", "v|verbose"])
.set_singles(vec!["o|output", "u|username"])
.set_multiples(vec!["i|input", "host"])
.parse();
// ...
}sourcepub fn set_flags(self, arg_specs: Vec<&str>) -> Self
pub fn set_flags(self, arg_specs: Vec<&str>) -> Self
Add flag argument parsing to the Clappers config
Flag arguments are true if they were supplied on the command line, and false otherwise
e.g:
-h
--help
-v
--verboseNote: flag arguments do not take values
Parameters
arg_specs specifies which flag arguments on the command line to care about.
Each arg_spec contains “|” separated flag argument alias names e.g:
clappers.set_flags(vec!["h|help", "v|verbose"]);Return value
The Clappers parser so that it can be chained
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help", "v|verbose"])
.set_singles(vec!["o|output", "u|username"])
.set_multiples(vec!["i|input", "host"])
.parse();
// ...
}sourcepub fn set_singles(self, arg_specs: Vec<&str>) -> Self
pub fn set_singles(self, arg_specs: Vec<&str>) -> Self
Add single value argument parsing to the Clappers config
Single value arguments contain a single String value if they were supplied on the command
line, and empty String otherwise e.g:
-o filename.txt
--output filename.txt
-u Zelensky
--username ZelenskyParameters
arg_specs specifies which single value arguments on the command line to care about.
Each arg_spec contains “|” separated single value argument alias names e.g:
clappers.set_singles(vec!["o|output", "u|username"]);Return value
The Clappers parser so that it can be chained
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help", "v|verbose"])
.set_singles(vec!["o|output", "u|username"])
.set_multiples(vec!["i|input", "host"])
.parse();
// ...
}sourcepub fn set_multiples(self, arg_specs: Vec<&str>) -> Self
pub fn set_multiples(self, arg_specs: Vec<&str>) -> Self
Add multiple value argument parsing to the Clappers config
Multiple value arguments contain at least a singly populated Vec<String> value if they
were supplied on the command line, and empty Vec<String> otherwise e.g:
-i file1.txt
--input file1.txt
--host host1They can also contain multiple values, by repetition on the command line e.g:
-i file1.txt -i file2.txt ... -i fileN.txt
--host host1 --host host2 ... --host hostNThe following format also works, reading from the first value until either the next argument is reached, or until the end of the entire command line arguments e.g:
-i file1.txt file2.txt ... fileN.txt -n next_argument
--host host1 host2 hostNParameters
arg_specs specifies which multiple value arguments on the command line to care about.
Each arg_spec contains “|” separated multiple value argument alias names e.g:
clappers.set_multiples(vec!["i|input", "host"]);Return value
The Clappers parser so that it can be chained
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help", "v|verbose"])
.set_singles(vec!["o|output", "u|username"])
.set_multiples(vec!["i|input", "host"])
.parse();
// ...
}sourcepub fn parse(self) -> Self
pub fn parse(self) -> Self
Parse the command line arguments with the current Clappers config
Parameters
None
Return value
The Clappers parser containing the parsed command line arguments values, accessed with:
get_flags()get_singles()get_multiples()get_leftovers()
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help", "v|verbose"])
.set_singles(vec!["o|output", "u|username"])
.set_multiples(vec!["i|input", "host"])
.parse();
if clappers.get_flag("help") {
// Show help text
}
// ...
}sourcepub fn get_flag(&self, argument: &str) -> bool
pub fn get_flag(&self, argument: &str) -> bool
Check if the flag was supplied on the command line for the specified argument
Parameters
argument is any alias of the specified argument
Return value
true if the flag was supplied on the command line, and false otherwise
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_flags(vec!["h|help"])
.parse();
if clappers.get_flag("help") {
// Show help text
}
if clappers.get_flag("h") {
// This will also show the help text
}
// ...
}sourcepub fn get_single(&self, argument: &str) -> String
pub fn get_single(&self, argument: &str) -> String
Get the single value supplied on the command line for the specified argument
Parameters
argument is any alias of the specified argument
Return value
The single String value if they were supplied on the command line, and empty String
otherwise
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_singles(vec!["output"])
.parse();
println!("Output filename is {}", clappers.get_single("output"));
// ...
}sourcepub fn get_multiple(&self, argument: &str) -> Vec<String>
pub fn get_multiple(&self, argument: &str) -> Vec<String>
Get multiple values supplied on the command line for the specified argument
Parameters
argument is any alias of the specified argument
Return value
Multiple String values if they were supplied on the command line, and empty Vec<String>
otherwise
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.set_multiples(vec!["input"])
.parse();
println!("Input filenames are {:#?}", clappers.get_multiple("input"));
// ...
}sourcepub fn get_leftovers(&self) -> Vec<String>
pub fn get_leftovers(&self) -> Vec<String>
Get all values supplied on the command line that are not associated with any argument
Parameters
None
Return value
All String values supplied on the command line that are not associated with any argument,
and empty Vec<String> otherwise
Example
use clappers::Clappers;
fn main() {
let clappers = Clappers::build()
.parse();
println!("`ls *` returned the following filenames: {:#?}", clappers.get_leftovers());
// ...
}Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Clappers
impl Send for Clappers
impl Sync for Clappers
impl Unpin for Clappers
impl UnwindSafe for Clappers
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more