mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:45:50 +02:00
nu_cli refactor in preparation for a crate called nu_command (#2907)
* move basic_shell_manager to nu-engine * move basic_evaluation_context to nu-engine * fix failing test in feature which commands/classified/external.rs
This commit is contained in:
20
crates/nu-engine/src/basic_evaluation_context.rs
Normal file
20
crates/nu-engine/src/basic_evaluation_context.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::basic_shell_manager;
|
||||
use crate::env::basic_host::BasicHost;
|
||||
use crate::EvaluationContext;
|
||||
use crate::Scope;
|
||||
use parking_lot::Mutex;
|
||||
use std::error::Error;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn basic_evaluation_context() -> Result<EvaluationContext, Box<dyn Error>> {
|
||||
Ok(EvaluationContext {
|
||||
scope: Scope::new(),
|
||||
host: Arc::new(parking_lot::Mutex::new(Box::new(BasicHost))),
|
||||
current_errors: Arc::new(Mutex::new(vec![])),
|
||||
ctrl_c: Arc::new(AtomicBool::new(false)),
|
||||
user_recently_used_autoenv_untrust: Arc::new(AtomicBool::new(false)),
|
||||
shell_manager: basic_shell_manager::basic_shell_manager()?,
|
||||
windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())),
|
||||
})
|
||||
}
|
14
crates/nu-engine/src/basic_shell_manager.rs
Normal file
14
crates/nu-engine/src/basic_shell_manager.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use crate::filesystem::filesystem_shell::FilesystemShell;
|
||||
use crate::shell::shell_manager::ShellManager;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use std::error::Error;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn basic_shell_manager() -> Result<ShellManager, Box<dyn Error>> {
|
||||
Ok(ShellManager {
|
||||
current_shell: Arc::new(AtomicUsize::new(0)),
|
||||
shells: Arc::new(Mutex::new(vec![Box::new(FilesystemShell::basic()?)])),
|
||||
})
|
||||
}
|
77
crates/nu-engine/src/env/basic_host.rs
vendored
Normal file
77
crates/nu-engine/src/env/basic_host.rs
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
use crate::Host;
|
||||
use nu_protocol::{errln, outln};
|
||||
use std::ffi::OsString;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BasicHost;
|
||||
|
||||
impl Host for BasicHost {
|
||||
fn stdout(&mut self, out: &str) {
|
||||
match out {
|
||||
"\n" => outln!(""),
|
||||
other => outln!("{}", other),
|
||||
}
|
||||
}
|
||||
|
||||
fn stderr(&mut self, out: &str) {
|
||||
match out {
|
||||
"\n" => errln!(""),
|
||||
other => errln!("{}", other),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn vars(&mut self) -> Vec<(String, String)> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
std::env::vars().collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn env_get(&mut self, key: OsString) -> Option<OsString> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
std::env::var_os(key)
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn env_set(&mut self, key: OsString, value: OsString) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
std::env::set_var(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn env_rm(&mut self, key: OsString) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
std::env::remove_var(key);
|
||||
}
|
||||
}
|
||||
|
||||
fn out_termcolor(&self) -> termcolor::StandardStream {
|
||||
termcolor::StandardStream::stdout(termcolor::ColorChoice::Auto)
|
||||
}
|
||||
|
||||
fn err_termcolor(&self) -> termcolor::StandardStream {
|
||||
termcolor::StandardStream::stderr(termcolor::ColorChoice::Auto)
|
||||
}
|
||||
|
||||
fn width(&self) -> usize {
|
||||
let (mut term_width, _) = term_size::dimensions().unwrap_or((80, 20));
|
||||
term_width -= 1;
|
||||
term_width
|
||||
}
|
||||
}
|
1
crates/nu-engine/src/env/mod.rs
vendored
1
crates/nu-engine/src/env/mod.rs
vendored
@ -1,2 +1,3 @@
|
||||
pub(crate) mod basic_host;
|
||||
pub(crate) mod environment;
|
||||
pub(crate) mod host;
|
||||
|
@ -1,3 +1,5 @@
|
||||
pub mod basic_evaluation_context;
|
||||
pub mod basic_shell_manager;
|
||||
mod call_info;
|
||||
mod command_args;
|
||||
pub mod deserializer;
|
||||
@ -13,6 +15,8 @@ pub mod plugin;
|
||||
pub mod shell;
|
||||
mod whole_stream_command;
|
||||
|
||||
pub use crate::basic_evaluation_context::basic_evaluation_context;
|
||||
pub use crate::basic_shell_manager::basic_shell_manager;
|
||||
pub use crate::call_info::UnevaluatedCallInfo;
|
||||
pub use crate::command_args::{
|
||||
CommandArgs, EvaluatedCommandArgs, EvaluatedWholeStreamCommandArgs, RawCommandArgs,
|
||||
|
Reference in New Issue
Block a user