pub struct Cli {
pub paths: Vec<PathBuf>,
pub bytes: bool,
pub chars: bool,
pub words: bool,
pub lines: bool,
pub longest_line: bool,
pub sub_commands: Option<SubCommands>,
}
Fields§
§paths: Vec<PathBuf>
§bytes: bool
Print the byte counts
chars: bool
Print the character counts
words: bool
Print the word counts
lines: bool
Print the line counts
longest_line: bool
Print the maximum line width (Unicode)
sub_commands: Option<SubCommands>
Implementations§
source§impl Cli
impl Cli
sourcepub fn enable_all_options(&mut self)
pub fn enable_all_options(&mut self)
Examples found in repository?
src/wc_result.rs (line 21)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
pub fn get(mut cli: Cli) -> Result<WcResult> {
println!("Please waiting...\n");
match cli.sub_commands {
Some(SubCommands::All { ref paths }) => {
cli.paths = paths.clone();
cli.enable_all_options();
}
None => cli.enable_all_options(),
};
println!("Calculating...");
let wc_result = WcResult {
enabled_options: cli.get_enabled_options(),
paths_with_counts: {
let contents = read_files(cli.paths.clone())?;
contents.into_par_iter().map(|(path, content)| (path, calculate_counts(&cli, content))).collect()
},
};
Ok(wc_result)
}
sourcepub fn get_enabled_options(&self) -> Vec<&'static str> ⓘ
pub fn get_enabled_options(&self) -> Vec<&'static str> ⓘ
Examples found in repository?
src/wc_result.rs (line 28)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
pub fn get(mut cli: Cli) -> Result<WcResult> {
println!("Please waiting...\n");
match cli.sub_commands {
Some(SubCommands::All { ref paths }) => {
cli.paths = paths.clone();
cli.enable_all_options();
}
None => cli.enable_all_options(),
};
println!("Calculating...");
let wc_result = WcResult {
enabled_options: cli.get_enabled_options(),
paths_with_counts: {
let contents = read_files(cli.paths.clone())?;
contents.into_par_iter().map(|(path, content)| (path, calculate_counts(&cli, content))).collect()
},
};
Ok(wc_result)
}
Trait Implementations§
source§impl CommandFactory for Cli
impl CommandFactory for Cli
source§impl FromArgMatches for Cli
impl FromArgMatches for Cli
source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches
) -> Result<Self, Error>
fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches
) -> Result<Self, Error>
source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches
) -> Result<(), Error>
Assign values from
ArgMatches
to self
.source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches
) -> Result<(), Error>
Assign values from
ArgMatches
to self
.source§impl Parser for Cli
impl Parser for Cli
source§fn try_parse() -> Result<Self, Error<RichFormatter>>
fn try_parse() -> Result<Self, Error<RichFormatter>>
Parse from
std::env::args_os()
, return Err on error.source§fn parse_from<I, T>(itr: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
fn parse_from<I, T>(itr: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
Parse from iterator, exit on error
source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error<RichFormatter>>where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error<RichFormatter>>where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
Parse from iterator, return Err on error.
source§fn update_from<I, T>(&mut self, itr: I)where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
fn update_from<I, T>(&mut self, itr: I)where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
Update from iterator, exit on error
source§fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error<RichFormatter>>where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error<RichFormatter>>where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
Update from iterator, return Err on error.