From cd527e849f0f05735cb1847a158b7104a00ce65c Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 25 Oct 2021 22:18:42 +0530 Subject: fix minor bug with out-format --- bin/src/config.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'bin/src') diff --git a/bin/src/config.rs b/bin/src/config.rs index 202ff6c..fc4057a 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -1,6 +1,6 @@ use std::{ default::Default, - fs, io, + fmt, fs, io, path::{Path, PathBuf}, str::FromStr, }; @@ -40,8 +40,8 @@ pub struct Check { ignore: Vec, /// Output format. - /// Supported values: errfmt, json (on feature flag only) - #[clap(short = 'o', long, default_value = "OutFormat::StdErr")] + /// Supported values: stderr, errfmt, json (on feature flag only) + #[clap(short = 'o', long, default_value_t, parse(try_from_str))] pub format: OutFormat, } @@ -192,7 +192,6 @@ fn vfs(files: Vec) -> Result { vfs.set_file_contents(&file, data.as_bytes()); } Ok(vfs) - } #[derive(Debug, Copy, Clone)] @@ -209,6 +208,21 @@ impl Default for OutFormat { } } +impl fmt::Display for OutFormat { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + #[cfg(feature = "json")] + Self::Json => "json", + Self::Errfmt => "errfmt", + Self::StdErr => "stderr", + } + ) + } +} + impl FromStr for OutFormat { type Err = &'static str; -- cgit v1.2.3