mirror of
https://github.com/nushell/nushell.git
synced 2025-08-11 09:54:32 +02:00
Move script to nu engine (#3092)
* Move run_script to engine * Add which dep and feature to engine * Change unwrap to expect * Add wasm specification * Remove which from default, add specification correctly * Add nu-platform-specifics * Move is_external_cmd to platform_specifics * Add is_external_cmd to host and use it instead of nu_platform directly * Clean up if else logic in is_external_cmd * Bump nu-platform-specifics version * Pass context to print_err * Commit cargo.lock * Move print functions to own module inside nu-engine * Hypocratic change to run windows-nightly again * Add import for Ordering * Move printing of error to host * Move platform specific which functionality to basic host * Allow no use of cmd_name * Fix windows compile issue
This commit is contained in:
@ -28,7 +28,7 @@ pub(crate) async fn run_external_command(
|
||||
) -> Result<InputStream, ShellError> {
|
||||
trace!(target: "nu::run::external", "-> {}", command.name);
|
||||
|
||||
if !did_find_command(&command.name) {
|
||||
if !context.host.lock().is_external_cmd(&command.name) {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Command not found",
|
||||
"command not found",
|
||||
@ -443,35 +443,6 @@ fn spawn(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn did_find_command(#[allow(unused)] name: &str) -> bool {
|
||||
#[cfg(not(feature = "which"))]
|
||||
{
|
||||
// we can't perform this check, so just assume it can be found
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "which", unix))]
|
||||
{
|
||||
which::which(name).is_ok()
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "which", windows))]
|
||||
{
|
||||
if which::which(name).is_ok() {
|
||||
true
|
||||
} else {
|
||||
// Reference: https://ss64.com/nt/syntax-internal.html
|
||||
let cmd_builtins = [
|
||||
"assoc", "break", "color", "copy", "date", "del", "dir", "dpath", "echo", "erase",
|
||||
"for", "ftype", "md", "mkdir", "mklink", "move", "path", "ren", "rename", "rd",
|
||||
"rmdir", "start", "time", "title", "type", "ver", "verify", "vol",
|
||||
];
|
||||
|
||||
cmd_builtins.contains(&name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_tilde<SI: ?Sized, P, HD>(input: &SI, home_dir: HD) -> std::borrow::Cow<str>
|
||||
where
|
||||
SI: AsRef<str>,
|
||||
|
@ -1,21 +0,0 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::Command;
|
||||
use nu_errors::ShellError;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
pub struct RunnableContext {
|
||||
pub input: InputStream,
|
||||
pub shell_manager: ShellManager,
|
||||
pub host: Arc<parking_lot::Mutex<Box<dyn Host>>>,
|
||||
pub ctrl_c: Arc<AtomicBool>,
|
||||
pub current_errors: Arc<Mutex<Vec<ShellError>>>,
|
||||
pub scope: Scope,
|
||||
pub name: Tag,
|
||||
}
|
||||
|
||||
impl RunnableContext {
|
||||
pub fn get_command(&self, name: &str) -> Option<Command> {
|
||||
self.scope.get_command(name)
|
||||
}
|
||||
}
|
@ -147,7 +147,7 @@ async fn maybe_autocd_dir<'a>(
|
||||
|| (cmd.args.is_empty()
|
||||
&& PathBuf::from(name).is_dir()
|
||||
&& dunce::canonicalize(name).is_ok()
|
||||
&& !crate::commands::classified::external::did_find_command(&name))
|
||||
&& !ctx.host.lock().is_external_cmd(&name))
|
||||
{
|
||||
Some(name)
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_engine::{script, WholeStreamCommand};
|
||||
|
||||
use nu_errors::ShellError;
|
||||
use nu_parser::expand_path;
|
||||
@ -50,7 +50,7 @@ pub async fn source(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let contents = std::fs::read_to_string(expand_path(&filename.item).into_owned());
|
||||
match contents {
|
||||
Ok(contents) => {
|
||||
let result = crate::script::run_script_standalone(contents, true, &ctx, false).await;
|
||||
let result = script::run_script_standalone(contents, true, &ctx, false).await;
|
||||
|
||||
if let Err(err) = result {
|
||||
ctx.error(err.into());
|
||||
|
@ -7,7 +7,9 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
use nu_table::{draw_table, Alignment, StyledString, TextStyle};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Instant;
|
||||
|
||||
#[cfg(feature = "table-pager")]
|
||||
use {
|
||||
futures::future::join,
|
||||
|
Reference in New Issue
Block a user