wip: color modular feature

This commit is contained in:
Kevin K 2021-08-09 19:33:53 -04:00
parent 72284d8db1
commit bdeece88e4
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
2 changed files with 50 additions and 0 deletions

View file

@ -29,6 +29,15 @@ pub(crate) struct Colorizer {
}
impl Colorizer {
#[inline]
pub(crate) fn from_string(use_stderr: bool, color_when: ColorChoice, s: String) -> Self {
Colorizer {
use_stderr,
color_when,
pieces: vec![(s, None)],
}
}
#[inline]
pub(crate) fn new(use_stderr: bool, color_when: ColorChoice) -> Self {
Colorizer {

View file

@ -873,6 +873,47 @@ impl Error {
}
}
#[cfg(not(any(feature = "color", feature = "full")))]
pub(crate) fn wrong_number_of_values(
arg: &Arg,
num_vals: usize,
curr_vals: usize,
usage: String,
color: ColorChoice,
) -> Self {
// let verb = Error::singular_or_plural(curr_vals);
// Error {
// message: Colorizer::from_string(
// true,
// color,
// format!("error: The argument '{}' requires {} values, but {} {} provided\n\n{}\n\nFor more information try --help\n", arg,num_vals, curr_vals, verb, usage)),
// kind: ErrorKind::WrongNumberOfValues,
// info: vec![arg.to_string(), curr_vals.to_string(), num_vals.to_string()],
// source: None,
// }
let mut c = Colorizer::new(true, color);
let verb = Error::singular_or_plural(curr_vals);
start_error(&mut c, "The argument '");
c.warning(arg.to_string());
c.none("' requires ");
c.warning(num_vals.to_string());
c.none(" values, but ");
c.warning(curr_vals.to_string());
c.none(format!(" {} provided", verb));
put_usage(&mut c, usage);
try_help(&mut c);
Error {
message: c,
kind: ErrorKind::WrongNumberOfValues,
info: vec![arg.to_string(), curr_vals.to_string(), num_vals.to_string()],
source: None,
}
}
#[cfg(any(feature = "color", feature = "full"))]
pub(crate) fn wrong_number_of_values(
arg: &Arg,
num_vals: usize,