@@ -2,6 +2,7 @@ use crate::archive::Archive;
2
2
use crate :: parse:: parse_base;
3
3
use crate :: verbosity:: Verbosity ;
4
4
use anyhow:: { anyhow, Context , Error , Result } ;
5
+ use clap:: builder:: PossibleValuesParser ;
5
6
use clap:: { arg, builder:: TypedValueParser , Parser } ;
6
7
use const_format:: { concatcp, formatcp} ;
7
8
use lychee_lib:: {
@@ -12,7 +13,7 @@ use secrecy::{ExposeSecret, SecretString};
12
13
use serde:: Deserialize ;
13
14
use std:: path:: Path ;
14
15
use std:: { fs, path:: PathBuf , str:: FromStr , time:: Duration } ;
15
- use strum:: VariantNames ;
16
+ use strum:: { Display , EnumIter , EnumString , EnumVariantNames , VariantNames } ;
16
17
17
18
pub ( crate ) const LYCHEE_IGNORE_FILE : & str = ".lycheeignore" ;
18
19
pub ( crate ) const LYCHEE_CACHE_FILE : & str = ".lycheecache" ;
@@ -74,27 +75,21 @@ impl FromStr for StatsFormat {
74
75
///
75
76
/// This decides over whether to use color,
76
77
/// emojis, or plain text for the output.
77
- #[ derive( Debug , Deserialize , Default , Clone ) ]
78
+ #[ derive( Debug , Deserialize , Default , Clone , Display , EnumIter , EnumString , EnumVariantNames ) ]
79
+ #[ non_exhaustive]
78
80
pub ( crate ) enum ResponseFormat {
81
+ #[ serde( rename = "plain" ) ]
82
+ #[ strum( serialize = "plain" , ascii_case_insensitive) ]
79
83
Plain ,
84
+ #[ serde( rename = "color" ) ]
85
+ #[ strum( serialize = "color" , ascii_case_insensitive) ]
80
86
#[ default]
81
87
Color ,
88
+ #[ serde( rename = "emoji" ) ]
89
+ #[ strum( serialize = "emoji" , ascii_case_insensitive) ]
82
90
Emoji ,
83
91
}
84
92
85
- impl FromStr for ResponseFormat {
86
- type Err = Error ;
87
-
88
- fn from_str ( mode : & str ) -> Result < Self , Self :: Err > {
89
- match mode. to_lowercase ( ) . as_str ( ) {
90
- "plain" | "plaintext" | "raw" => Ok ( ResponseFormat :: Plain ) ,
91
- "color" => Ok ( ResponseFormat :: Color ) ,
92
- "emoji" => Ok ( ResponseFormat :: Emoji ) ,
93
- _ => Err ( anyhow ! ( "Unknown formatter mode {mode}" ) ) ,
94
- }
95
- }
96
- }
97
-
98
93
// Macro for generating default functions to be used by serde
99
94
macro_rules! default_function {
100
95
( $( $name: ident : $T: ty = $e: expr; ) * ) => {
@@ -218,7 +213,7 @@ pub(crate) struct Config {
218
213
219
214
/// Specify the use of a specific web archive.
220
215
/// Can be used in combination with `--suggest`
221
- #[ arg( long, value_parser = clap :: builder :: PossibleValuesParser :: new( Archive :: VARIANTS ) . map( |s| s. parse:: <Archive >( ) . unwrap( ) ) ) ]
216
+ #[ arg( long, value_parser = PossibleValuesParser :: new( Archive :: VARIANTS ) . map( |s| s. parse:: <Archive >( ) . unwrap( ) ) ) ]
222
217
#[ serde( default ) ]
223
218
pub ( crate ) archive : Option < Archive > ,
224
219
@@ -413,8 +408,8 @@ separated list of accepted status codes. This example will accept 200, 201,
413
408
#[ serde( default ) ]
414
409
pub ( crate ) output : Option < PathBuf > ,
415
410
416
- /// Set the output display mode. Determines how results are presented in the terminal (color, plain, emoji).
417
- #[ arg( long, default_value = "color" ) ]
411
+ /// Set the output display mode. Determines how results are presented in the terminal
412
+ #[ arg( long, default_value = "color" , value_parser = PossibleValuesParser :: new ( ResponseFormat :: VARIANTS ) . map ( |s| s . parse :: < ResponseFormat > ( ) . unwrap ( ) ) ) ]
418
413
#[ serde( default ) ]
419
414
pub ( crate ) mode : ResponseFormat ,
420
415
0 commit comments