mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 00:54:56 +02:00
Runnable contexts move. (#3283)
* Engine extract first steps. * Don't depend on ShellManager.
This commit is contained in:
committed by
GitHub
parent
09a1f5acb9
commit
2880109f31
@ -31,6 +31,18 @@ pub struct CommandArgs {
|
||||
pub input: InputStream,
|
||||
}
|
||||
|
||||
pub type RunnableContext = CommandArgs;
|
||||
|
||||
pub struct RunnableContextWithoutInput {
|
||||
pub shell_manager: ShellManager,
|
||||
pub host: Arc<parking_lot::Mutex<Box<dyn Host>>>,
|
||||
pub current_errors: Arc<Mutex<Vec<ShellError>>>,
|
||||
pub ctrl_c: Arc<AtomicBool>,
|
||||
pub configs: Arc<Mutex<ConfigHolder>>,
|
||||
pub scope: Scope,
|
||||
pub name: Tag,
|
||||
}
|
||||
|
||||
#[derive(Getters, Clone)]
|
||||
#[get = "pub"]
|
||||
pub struct RawCommandArgs {
|
||||
@ -86,6 +98,20 @@ impl CommandArgs {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn split(self) -> (InputStream, RunnableContextWithoutInput) {
|
||||
let new_context = RunnableContextWithoutInput {
|
||||
shell_manager: self.shell_manager,
|
||||
host: self.host,
|
||||
ctrl_c: self.ctrl_c,
|
||||
configs: self.configs,
|
||||
current_errors: self.current_errors,
|
||||
scope: self.scope,
|
||||
name: self.call_info.name_tag,
|
||||
};
|
||||
|
||||
(self.input, new_context)
|
||||
}
|
||||
|
||||
pub fn process<'de, T: Deserialize<'de>>(self) -> Result<(T, InputStream), ShellError> {
|
||||
let args = self.evaluate_once()?;
|
||||
let call_info = args.call_info.clone();
|
||||
|
@ -14,7 +14,6 @@ mod from_value;
|
||||
mod maybe_text_codec;
|
||||
pub mod plugin;
|
||||
mod print;
|
||||
mod runnable_context;
|
||||
pub mod script;
|
||||
pub mod shell;
|
||||
mod whole_stream_command;
|
||||
@ -24,6 +23,7 @@ pub use crate::basic_shell_manager::basic_shell_manager;
|
||||
pub use crate::call_info::UnevaluatedCallInfo;
|
||||
pub use crate::command_args::{
|
||||
CommandArgs, EvaluatedCommandArgs, EvaluatedWholeStreamCommandArgs, RawCommandArgs,
|
||||
RunnableContext, RunnableContextWithoutInput,
|
||||
};
|
||||
pub use crate::config_holder::ConfigHolder;
|
||||
pub use crate::documentation::{generate_docs, get_brief_help, get_documentation, get_full_help};
|
||||
@ -40,7 +40,6 @@ pub use crate::filesystem::path;
|
||||
pub use crate::from_value::FromValue;
|
||||
pub use crate::maybe_text_codec::{BufCodecReader, MaybeTextCodec, StringOrBinary};
|
||||
pub use crate::print::maybe_print_errors;
|
||||
pub use crate::runnable_context::RunnableContext;
|
||||
pub use crate::shell::painter::Painter;
|
||||
pub use crate::shell::palette::{DefaultPalette, Palette};
|
||||
pub use crate::shell::shell_manager::ShellManager;
|
||||
|
@ -1,50 +0,0 @@
|
||||
use crate::{Command, CommandArgs, EvaluationContext};
|
||||
use crate::{ConfigHolder, Host, Scope, ShellManager};
|
||||
use nu_errors::ShellError;
|
||||
use nu_source::Tag;
|
||||
use nu_stream::InputStream;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::{atomic::AtomicBool, Arc};
|
||||
|
||||
pub struct RunnableContext {
|
||||
pub input: InputStream,
|
||||
pub shell_manager: ShellManager,
|
||||
pub host: Arc<Mutex<Box<dyn Host>>>,
|
||||
pub ctrl_c: Arc<AtomicBool>,
|
||||
pub configs: Arc<Mutex<ConfigHolder>>,
|
||||
pub current_errors: Arc<Mutex<Vec<ShellError>>>,
|
||||
pub scope: Scope,
|
||||
pub name: Tag,
|
||||
}
|
||||
|
||||
impl RunnableContext {
|
||||
pub fn from_command_args(args: CommandArgs) -> Self {
|
||||
RunnableContext {
|
||||
input: args.input,
|
||||
scope: args.scope.clone(),
|
||||
shell_manager: args.shell_manager,
|
||||
host: args.host,
|
||||
ctrl_c: args.ctrl_c,
|
||||
configs: args.configs,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_evaluation_context(input: InputStream, ctx: &EvaluationContext) -> Self {
|
||||
RunnableContext {
|
||||
input,
|
||||
shell_manager: ctx.shell_manager.clone(),
|
||||
host: ctx.host.clone(),
|
||||
ctrl_c: ctx.ctrl_c.clone(),
|
||||
configs: ctx.configs.clone(),
|
||||
current_errors: ctx.current_errors.clone(),
|
||||
scope: ctx.scope.clone(),
|
||||
name: Tag::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_command(&self, name: &str) -> Option<Command> {
|
||||
self.scope.get_command(name)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user