mirror of
https://github.com/XAMPPRocky/tokei
synced 2024-10-12 10:53:41 +00:00
parent
3e2e1ad564
commit
611de1fc7b
|
@ -20,6 +20,7 @@ pub struct Cli<'a> {
|
||||||
pub print_languages: bool,
|
pub print_languages: bool,
|
||||||
pub sort: Option<Sort>,
|
pub sort: Option<Sort>,
|
||||||
pub types: Option<Vec<LanguageType>>,
|
pub types: Option<Vec<LanguageType>>,
|
||||||
|
pub compact: bool,
|
||||||
pub number_format: num_format::CustomFormat,
|
pub number_format: num_format::CustomFormat,
|
||||||
pub verbose: u64,
|
pub verbose: u64,
|
||||||
}
|
}
|
||||||
|
@ -83,6 +84,8 @@ impl<'a> Cli<'a> {
|
||||||
(@arg types: -t --type
|
(@arg types: -t --type
|
||||||
+takes_value
|
+takes_value
|
||||||
"Filters output by language type, seperated by a comma. i.e. -t=Rust,Markdown")
|
"Filters output by language type, seperated by a comma. i.e. -t=Rust,Markdown")
|
||||||
|
(@arg compact: -C --compact
|
||||||
|
"Do not print statistics about embedded languages.")
|
||||||
(@arg num_format_style: -n --("num-format")
|
(@arg num_format_style: -n --("num-format")
|
||||||
possible_values(NumberFormatStyle::all())
|
possible_values(NumberFormatStyle::all())
|
||||||
conflicts_with[output]
|
conflicts_with[output]
|
||||||
|
@ -106,6 +109,7 @@ impl<'a> Cli<'a> {
|
||||||
let no_ignore_vcs = matches.is_present("no_ignore_vcs");
|
let no_ignore_vcs = matches.is_present("no_ignore_vcs");
|
||||||
let print_languages = matches.is_present("languages");
|
let print_languages = matches.is_present("languages");
|
||||||
let verbose = matches.occurrences_of("verbose");
|
let verbose = matches.occurrences_of("verbose");
|
||||||
|
let compact = matches.is_present("compact");
|
||||||
let types = matches.value_of("types").map(|e| {
|
let types = matches.value_of("types").map(|e| {
|
||||||
e.split(',')
|
e.split(',')
|
||||||
.map(|t| t.parse::<LanguageType>())
|
.map(|t| t.parse::<LanguageType>())
|
||||||
|
@ -151,6 +155,7 @@ impl<'a> Cli<'a> {
|
||||||
types,
|
types,
|
||||||
verbose,
|
verbose,
|
||||||
number_format,
|
number_format,
|
||||||
|
compact,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("CLI Config: {:#?}", cli);
|
debug!("CLI Config: {:#?}", cli);
|
||||||
|
|
|
@ -293,18 +293,18 @@ impl<W: Write> Printer<W> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_results<'a, I>(&mut self, languages: I) -> io::Result<()>
|
pub fn print_results<'a, I>(&mut self, languages: I, compact: bool) -> io::Result<()>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (&'a LanguageType, &'a Language)>,
|
I: Iterator<Item = (&'a LanguageType, &'a Language)>,
|
||||||
{
|
{
|
||||||
let (a, b): (Vec<_>, Vec<_>) = languages
|
let (a, b): (Vec<_>, Vec<_>) = languages
|
||||||
.filter(|(_, v)| !v.is_empty())
|
.filter(|(_, v)| !v.is_empty())
|
||||||
.partition(|(_, l)| l.children.is_empty());
|
.partition(|(_, l)| compact || l.children.is_empty());
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
||||||
for languages in &[&a, &b] {
|
for languages in &[&a, &b] {
|
||||||
for &(name, language) in *languages {
|
for &(name, language) in *languages {
|
||||||
let has_children = !language.children.is_empty();
|
let has_children = !(compact || language.children.is_empty());
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
} else if has_children || self.list_files {
|
} else if has_children || self.list_files {
|
||||||
|
|
|
@ -86,9 +86,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Sort::Lines => languages.sort_by(|a, b| b.1.lines().cmp(&a.1.lines())),
|
Sort::Lines => languages.sort_by(|a, b| b.1.lines().cmp(&a.1.lines())),
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.print_results(languages.into_iter())?
|
printer.print_results(languages.into_iter(), cli.compact)?
|
||||||
} else {
|
} else {
|
||||||
printer.print_results(languages.iter())?
|
printer.print_results(languages.iter(), cli.compact)?
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.print_total(languages)?;
|
printer.print_total(languages)?;
|
||||||
|
|
Loading…
Reference in a new issue