Derive Clone and implement From<String> for automatic Clap parsing.
This commit is contained in:
parent
6b6c48c476
commit
a9ee3c20fe
|
@ -3,7 +3,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// The noise level Hooked should output logs with.
|
/// The noise level Hooked should output logs with.
|
||||||
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum NoiseLevel {
|
pub enum NoiseLevel {
|
||||||
/// Output only errors.
|
/// Output only errors.
|
||||||
|
@ -22,3 +22,16 @@ impl Default for NoiseLevel {
|
||||||
Self::Standard
|
Self::Standard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement `From<String>` so we can use Clap's automatic parsing in the CLI.
|
||||||
|
impl From<String> for NoiseLevel {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
match value.to_lowercase().as_str() {
|
||||||
|
"quiet" => Self::Quiet,
|
||||||
|
"loud" => Self::Loud,
|
||||||
|
"standard" => Self::Standard,
|
||||||
|
"minimal" => Self::Minimal,
|
||||||
|
_ => NoiseLevel::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue