mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-21 22:10:45 +01:00
When specifying style multiple times the last occurence wins
Closes: #367
This commit is contained in:
parent
c1246fcd53
commit
7c98a1c901
10
src/app.rs
10
src/app.rs
@ -270,8 +270,14 @@ impl App {
|
|||||||
.collect::<Result<Vec<OutputComponent>>>()
|
.collect::<Result<Vec<OutputComponent>>>()
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
values_t!(matches.values_of("style"), OutputComponent)
|
matches.value_of("style")
|
||||||
.ok()
|
.map(|styles| {
|
||||||
|
styles
|
||||||
|
.split(",")
|
||||||
|
.map(|style| style.parse::<OutputComponent>())
|
||||||
|
.filter_map(|style| style.ok())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
.or(env_style_components)
|
.or(env_style_components)
|
||||||
.unwrap_or(vec![OutputComponent::Full])
|
.unwrap_or(vec![OutputComponent::Full])
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -99,11 +99,26 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||||||
Arg::with_name("style")
|
Arg::with_name("style")
|
||||||
.long("style")
|
.long("style")
|
||||||
.value_name("style-components")
|
.value_name("style-components")
|
||||||
.use_delimiter(true)
|
// Need to turn this off for overrides_with to work as we want. See the bottom most
|
||||||
|
// example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
|
||||||
|
.use_delimiter(false)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&[
|
.overrides_with("style")
|
||||||
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
// Cannot use clap's built in validation because we have to turn off clap's delimiters
|
||||||
])
|
.validator(|val| {
|
||||||
|
let mut invalid_vals = val.split(",").filter(|style| {
|
||||||
|
!&[
|
||||||
|
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
||||||
|
]
|
||||||
|
.contains(style)
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(invalid) = invalid_vals.next() {
|
||||||
|
Err(format!("Unknown style, '{}'", invalid))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
})
|
||||||
.help(
|
.help(
|
||||||
"Comma-separated list of style elements to display \
|
"Comma-separated list of style elements to display \
|
||||||
(*auto*, full, plain, changes, header, grid, numbers).",
|
(*auto*, full, plain, changes, header, grid, numbers).",
|
||||||
|
Loading…
Reference in New Issue
Block a user