diff --git a/src/app.rs b/src/app.rs index 448566a2..e9c3abea 100644 --- a/src/app.rs +++ b/src/app.rs @@ -270,8 +270,14 @@ impl App { .collect::>>() }))?; - values_t!(matches.values_of("style"), OutputComponent) - .ok() + matches.value_of("style") + .map(|styles| { + styles + .split(",") + .map(|style| style.parse::()) + .filter_map(|style| style.ok()) + .collect::>() + }) .or(env_style_components) .unwrap_or(vec![OutputComponent::Full]) .into_iter() diff --git a/src/clap_app.rs b/src/clap_app.rs index bde3f5cb..0c6a8e15 100644 --- a/src/clap_app.rs +++ b/src/clap_app.rs @@ -99,11 +99,26 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { Arg::with_name("style") .long("style") .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) - .possible_values(&[ - "auto", "full", "plain", "changes", "header", "grid", "numbers", - ]) + .overrides_with("style") + // 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( "Comma-separated list of style elements to display \ (*auto*, full, plain, changes, header, grid, numbers).",