mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Refactor rarely changing engine state into its own struct (#3612)
* WIP * Finish up EngineState refactor * Fix Windows calls * Fix Windows calls * Fix Windows calls
This commit is contained in:
@ -59,7 +59,7 @@ pub fn autoview(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
if let Some(x) = input_stream.next() {
|
||||
match input_stream.next() {
|
||||
Some(y) => {
|
||||
let ctrl_c = context.ctrl_c.clone();
|
||||
let ctrl_c = context.ctrl_c().clone();
|
||||
let xy = vec![x, y];
|
||||
let xy_stream = xy.into_iter().chain(input_stream).interruptible(ctrl_c);
|
||||
|
||||
@ -192,7 +192,7 @@ pub fn autoview(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
} => {
|
||||
let pivot_mode = configuration.pivot_mode();
|
||||
|
||||
let term_width = context.host.lock().width();
|
||||
let term_width = context.host().lock().width();
|
||||
if pivot_mode.is_always()
|
||||
|| (pivot_mode.is_auto()
|
||||
&& (row
|
||||
|
@ -27,7 +27,7 @@ pub(crate) fn run_external_command(
|
||||
trace!(target: "nu::run::external", "-> {}", command.name);
|
||||
|
||||
context.sync_path_to_env();
|
||||
if !context.host.lock().is_external_cmd(&command.name) {
|
||||
if !context.host().lock().is_external_cmd(&command.name) {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Command not found",
|
||||
format!("command {} not found", &command.name),
|
||||
@ -59,7 +59,7 @@ fn run_with_stdin(
|
||||
input: InputStream,
|
||||
external_redirection: ExternalRedirection,
|
||||
) -> Result<InputStream, ShellError> {
|
||||
let path = context.shell_manager.path();
|
||||
let path = context.shell_manager().path();
|
||||
|
||||
let mut command_args = vec![];
|
||||
for arg in command.args.iter() {
|
||||
|
@ -41,7 +41,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
||||
let column_path = args.req(0)?;
|
||||
|
||||
let result = if let Some(global_cfg) = &ctx.configs.lock().global_config {
|
||||
let result = if let Some(global_cfg) = &ctx.configs().lock().global_config {
|
||||
let result = UntaggedValue::row(global_cfg.vars.clone()).into_value(&name);
|
||||
let value = crate::commands::get::get_column_path(&column_path, &result)?;
|
||||
Ok(match value {
|
||||
|
@ -43,7 +43,7 @@ pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
||||
let key = remove.to_string();
|
||||
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs.lock().global_config {
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs().lock().global_config {
|
||||
if global_cfg.vars.contains_key(&key) {
|
||||
global_cfg.vars.swap_remove(&key);
|
||||
global_cfg.write()?;
|
||||
|
@ -57,7 +57,7 @@ pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let column_path = args.req(0)?;
|
||||
let mut value: Value = args.req(1)?;
|
||||
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs.lock().global_config {
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs().lock().global_config {
|
||||
let configuration = UntaggedValue::row(global_cfg.vars.clone()).into_value(&name);
|
||||
|
||||
if let UntaggedValue::Table(rows) = &value.value {
|
||||
|
@ -45,7 +45,7 @@ pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let rows: Vec<Value> = args.input.collect();
|
||||
let key = set_into.to_string();
|
||||
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs.lock().global_config {
|
||||
let result = if let Some(global_cfg) = &mut ctx.configs().lock().global_config {
|
||||
if rows.is_empty() {
|
||||
return Err(ShellError::labeled_error(
|
||||
"No values given for set_into",
|
||||
|
@ -31,6 +31,7 @@ impl WholeStreamCommand for DataFrame {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_collect)]
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
|
||||
|
@ -73,7 +73,7 @@ fn enter(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let head = args.call_info.args.head.clone();
|
||||
let context = args.context.clone();
|
||||
let scope = args.scope().clone();
|
||||
let path = args.context.shell_manager.path();
|
||||
let path = args.context.shell_manager().path();
|
||||
|
||||
let location: Tagged<PathBuf> = args.req(0)?;
|
||||
let encoding: Option<Tagged<String>> = args.get_flag("encoding")?;
|
||||
|
@ -31,7 +31,7 @@ fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
|
||||
let clear = args.has_flag("clear");
|
||||
|
||||
let path = if let Some(global_cfg) = &ctx.configs.lock().global_config {
|
||||
let path = if let Some(global_cfg) = &ctx.configs().lock().global_config {
|
||||
nu_data::config::path::history_path_or_default(global_cfg)
|
||||
} else {
|
||||
nu_data::config::path::default_history_path()
|
||||
|
@ -102,7 +102,7 @@ impl WholeStreamCommand for RunExternalCommand {
|
||||
};
|
||||
|
||||
let result = external_context
|
||||
.shell_manager
|
||||
.shell_manager()
|
||||
.cd(cd_args, args.call_info.name_tag);
|
||||
|
||||
return Ok(result?.to_action_stream());
|
||||
@ -138,7 +138,7 @@ fn maybe_autocd_dir(cmd: &ExternalCommand, ctx: &mut EvaluationContext) -> Optio
|
||||
|| (cmd.args.is_empty()
|
||||
&& PathBuf::from(name).is_dir()
|
||||
&& dunce::canonicalize(name).is_ok()
|
||||
&& !ctx.host.lock().is_external_cmd(name))
|
||||
&& !ctx.host().lock().is_external_cmd(name))
|
||||
{
|
||||
Some(name)
|
||||
} else {
|
||||
@ -151,11 +151,11 @@ fn maybe_autocd_dir(cmd: &ExternalCommand, ctx: &mut EvaluationContext) -> Optio
|
||||
if name.ends_with(':') {
|
||||
// This looks like a drive shortcut. We need to a) switch drives and b) go back to the previous directory we were viewing on that drive
|
||||
// But first, we need to save where we are now
|
||||
let current_path = ctx.shell_manager.path();
|
||||
let current_path = ctx.shell_manager().path();
|
||||
|
||||
let split_path: Vec<_> = current_path.split(':').collect();
|
||||
if split_path.len() > 1 {
|
||||
ctx.windows_drives_previous_cwd
|
||||
ctx.windows_drives_previous_cwd()
|
||||
.lock()
|
||||
.insert(split_path[0].to_string(), current_path);
|
||||
}
|
||||
@ -163,7 +163,7 @@ fn maybe_autocd_dir(cmd: &ExternalCommand, ctx: &mut EvaluationContext) -> Optio
|
||||
let name = name.to_uppercase();
|
||||
let new_drive: Vec<_> = name.split(':').collect();
|
||||
|
||||
if let Some(val) = ctx.windows_drives_previous_cwd.lock().get(new_drive[0]) {
|
||||
if let Some(val) = ctx.windows_drives_previous_cwd().lock().get(new_drive[0]) {
|
||||
val.to_string()
|
||||
} else {
|
||||
name
|
||||
|
Reference in New Issue
Block a user