mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-22 21:48:56 +01:00
Added validation for --tabs.
Also added a comment to explain what 0 represents.
This commit is contained in:
parent
9ef1e9f792
commit
d404139ff7
15
src/app.rs
15
src/app.rs
@ -42,6 +42,7 @@ pub struct Config<'a> {
|
|||||||
pub term_width: usize,
|
pub term_width: usize,
|
||||||
|
|
||||||
/// The width of tab characters.
|
/// The width of tab characters.
|
||||||
|
/// Currently, a value of 0 will cause tabs to be passed through without expanding them.
|
||||||
pub tab_width: usize,
|
pub tab_width: usize,
|
||||||
|
|
||||||
/// Whether or not to simply loop through all input (`cat` mode)
|
/// Whether or not to simply loop through all input (`cat` mode)
|
||||||
@ -282,9 +283,14 @@ impl App {
|
|||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("tabs")
|
Arg::with_name("tabs")
|
||||||
.long("tabs")
|
.long("tabs")
|
||||||
.short("t")
|
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("width")
|
.value_name("tabs")
|
||||||
|
.validator(
|
||||||
|
|t| t.parse::<u32>()
|
||||||
|
.map_err(|_t| "must be a number")
|
||||||
|
.map(|_t| ()) // Convert to Result<(), &str>
|
||||||
|
.map_err(|e| e.to_string()) // Convert to Result<(), String>
|
||||||
|
)
|
||||||
.help("Sets the tab width.")
|
.help("Sets the tab width.")
|
||||||
.long_help("Sets the tab width. Use a width of 0 to pass tabs through \
|
.long_help("Sets the tab width. Use a width of 0 to pass tabs through \
|
||||||
directly"),
|
directly"),
|
||||||
@ -410,8 +416,9 @@ impl App {
|
|||||||
tab_width: self
|
tab_width: self
|
||||||
.matches
|
.matches
|
||||||
.value_of("tabs")
|
.value_of("tabs")
|
||||||
.and_then(|w| w.parse().ok())
|
.map(String::from)
|
||||||
.or_else(|| env::var("BAT_TABS").ok().and_then(|w| w.parse().ok()))
|
.or_else(|| env::var("BAT_TABS").ok())
|
||||||
|
.and_then(|t| t.parse().ok())
|
||||||
.unwrap_or(
|
.unwrap_or(
|
||||||
if output_components.plain() && paging_mode == PagingMode::Never {
|
if output_components.plain() && paging_mode == PagingMode::Never {
|
||||||
0
|
0
|
||||||
|
Loading…
Reference in New Issue
Block a user