mirror of
https://github.com/nushell/nushell.git
synced 2025-05-29 06:17:54 +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.
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use super::prelude::*;
|
|
use crate as nu_protocol;
|
|
|
|
#[derive(Clone, Copy, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct LsConfig {
|
|
pub use_ls_colors: bool,
|
|
pub clickable_links: bool,
|
|
}
|
|
|
|
impl Default for LsConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
use_ls_colors: true,
|
|
clickable_links: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UpdateFromValue for LsConfig {
|
|
fn update<'a>(
|
|
&mut self,
|
|
value: &'a Value,
|
|
path: &mut ConfigPath<'a>,
|
|
errors: &mut ConfigErrors,
|
|
) {
|
|
let Value::Record { val: record, .. } = value else {
|
|
errors.type_mismatch(path, Type::record(), value);
|
|
return;
|
|
};
|
|
|
|
for (col, val) in record.iter() {
|
|
let path = &mut path.push(col);
|
|
match col.as_str() {
|
|
"use_ls_colors" => self.use_ls_colors.update(val, path, errors),
|
|
"clickable_links" => self.clickable_links.update(val, path, errors),
|
|
_ => errors.unknown_option(path, val),
|
|
}
|
|
}
|
|
}
|
|
}
|