mirror of
https://github.com/nushell/nushell.git
synced 2025-04-11 14:58:21 +02:00
# Description This PR standardizes updates to the config through a new `UpdateFromValue` trait. For now, this trait is private in case we need to make changes to it. Note that this PR adds some additional `ShellError` cases to create standard error messages for config errors. A follow-up PR will move usages of the old error cases to these new ones. This PR also uses `Type::custom` in lots of places (e.g., for string enums). Not sure if this is something we want to encourage. # User-Facing Changes Should be none.
27 lines
710 B
Rust
27 lines
710 B
Rust
use super::{config_update_string_enum, prelude::*};
|
|
use crate as nu_protocol;
|
|
|
|
#[derive(Clone, Copy, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum ErrorStyle {
|
|
Plain,
|
|
Fancy,
|
|
}
|
|
|
|
impl FromStr for ErrorStyle {
|
|
type Err = &'static str;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
match s.to_ascii_lowercase().as_str() {
|
|
"fancy" => Ok(Self::Fancy),
|
|
"plain" => Ok(Self::Plain),
|
|
_ => Err("'fancy' or 'plain'"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UpdateFromValue for ErrorStyle {
|
|
fn update(&mut self, value: &Value, path: &mut ConfigPath, errors: &mut ConfigErrors) {
|
|
config_update_string_enum(self, value, path, errors)
|
|
}
|
|
}
|