1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-07-11 14:30:24 +02:00

add --histogram flag definition

This commit is contained in:
Cabbache
2024-10-23 17:15:16 +02:00
parent 79cbe89deb
commit fcb758a62d
2 changed files with 38 additions and 0 deletions

View File

@ -59,6 +59,7 @@ pub(super) const FLAGS: &[&dyn Flag] = &[
&ContextSeparator,
&Count,
&CountMatches,
&Histogram,
&Crlf,
&Debug,
&DfaSizeLimit,
@ -1322,6 +1323,42 @@ given.
}
}
/// --histogram
#[derive(Debug)]
struct Histogram;
impl Flag for Histogram {
fn is_switch(&self) -> bool {
false
}
fn name_short(&self) -> Option<u8> {
None
}
fn name_long(&self) -> &'static str {
"histogram"
}
fn doc_variable(&self) -> Option<&'static str> {
Some("NUM")
}
fn doc_category(&self) -> Category {
Category::OutputModes
}
fn doc_short(&self) -> &'static str {
r"Print a histogram of the matches"
}
fn doc_long(&self) -> &'static str {
r"
--histogram NUM means that the bins of the histograms are NUM characters wide. In the output the numbers are the counts in these bins.
"
}
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
let binsize = convert::usize(&v.unwrap_value())?;
args.histogram = if binsize == 0 { None } else { Some(binsize) };
Ok(())
}
}
#[cfg(test)]
#[test]
fn test_count_matches() {

View File

@ -59,6 +59,7 @@ pub(crate) struct LowArgs {
pub(crate) globs: Vec<String>,
pub(crate) heading: Option<bool>,
pub(crate) hidden: bool,
pub(crate) histogram: Option<usize>,
pub(crate) hostname_bin: Option<PathBuf>,
pub(crate) hyperlink_format: HyperlinkFormat,
pub(crate) iglobs: Vec<String>,