mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-30 22:23:44 +02:00
committed by
Andrew Gallant
parent
5e73075ef5
commit
ba1023e1e4
17
src/app.rs
17
src/app.rs
@ -102,6 +102,9 @@ pub fn app() -> App<'static, 'static> {
|
||||
.value_name("GLOB"))
|
||||
.arg(flag("ignore-case").short("i"))
|
||||
.arg(flag("line-number").short("n"))
|
||||
.arg(flag("line-number-width")
|
||||
.value_name("NUM").takes_value(true)
|
||||
.validator(validate_line_number_width))
|
||||
.arg(flag("no-line-number").short("N").overrides_with("line-number"))
|
||||
.arg(flag("quiet").short("q"))
|
||||
.arg(flag("type").short("t")
|
||||
@ -318,6 +321,11 @@ lazy_static! {
|
||||
"Show line numbers.",
|
||||
"Show line numbers (1-based). This is enabled by default when \
|
||||
searching in a tty.");
|
||||
doc!(h, "line-number-width",
|
||||
"Left pad line numbers upto NUM width.",
|
||||
"Left pad line numbers upto NUM width. Space is used as \
|
||||
the default padding character. This has no effect if \
|
||||
--no-line-number is enabled.");
|
||||
doc!(h, "no-line-number",
|
||||
"Suppress line numbers.",
|
||||
"Suppress line numbers. This is enabled by default when NOT \
|
||||
@ -575,6 +583,15 @@ lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
fn validate_line_number_width(s: String) -> Result<(), String> {
|
||||
if s.starts_with("0") {
|
||||
Err(String::from("Custom padding characters are currently not supported. \
|
||||
Please enter only a numeric value."))
|
||||
} else {
|
||||
validate_number(s)
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_number(s: String) -> Result<(), String> {
|
||||
s.parse::<usize>().map(|_|()).map_err(|err| err.to_string())
|
||||
}
|
||||
|
Reference in New Issue
Block a user