mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Use IntoValue
in config code (#13751)
# Description Cleans up and refactors the config code using the `IntoValue` macro. Shoutout to @cptpiepmatz for making the macro! # User-Facing Changes Should be none. # After Submitting Somehow refactor the reverse transformation.
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
use crate::{Config, Record, ShellError, Span, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::prelude::*;
|
||||
use crate as nu_protocol;
|
||||
use crate::ShellError;
|
||||
|
||||
/// Definition of a parsed hook from the config object
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Clone, Debug, IntoValue, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Hooks {
|
||||
pub pre_prompt: Option<Value>,
|
||||
pub pre_execution: Option<Value>,
|
||||
@ -65,24 +66,3 @@ pub(super) fn create_hooks(value: &Value) -> Result<Hooks, ShellError> {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reconstruct_hooks(config: &Config, span: Span) -> Value {
|
||||
let mut hook = Record::new();
|
||||
if let Some(ref value) = config.hooks.pre_prompt {
|
||||
hook.push("pre_prompt", value.clone());
|
||||
}
|
||||
if let Some(ref value) = config.hooks.pre_execution {
|
||||
hook.push("pre_execution", value.clone());
|
||||
}
|
||||
if let Some(ref value) = config.hooks.env_change {
|
||||
hook.push("env_change", value.clone());
|
||||
}
|
||||
if let Some(ref value) = config.hooks.display_output {
|
||||
hook.push("display_output", value.clone());
|
||||
}
|
||||
if let Some(ref value) = config.hooks.command_not_found {
|
||||
hook.push("command_not_found", value.clone());
|
||||
}
|
||||
|
||||
Value::record(hook, span)
|
||||
}
|
||||
|
Reference in New Issue
Block a user