Fix tests and run_external message bug

This commit is contained in:
Ian Manske 2024-11-16 14:27:41 -08:00
parent cba76b6e23
commit c11a17e6c5
3 changed files with 21 additions and 13 deletions

View File

@ -45,6 +45,7 @@ On Windows based systems, Nushell will wait for the command to finish and then e
call.head,
engine_state,
stack,
&cwd,
));
};
executable

View File

@ -1,6 +1,6 @@
use nu_cmd_base::hook::eval_hook;
use nu_engine::{command_prelude::*, env_to_strings, get_eval_expression};
use nu_path::{dots::expand_ndots, expand_tilde};
use nu_path::{dots::expand_ndots, expand_tilde, AbsolutePath};
use nu_protocol::{did_you_mean, process::ChildProcess, ByteStream, NuGlob, OutDest, Signals};
use nu_system::ForegroundChild;
use nu_utils::IgnoreCaseExt;
@ -78,7 +78,13 @@ impl Command for External {
// effect if it's an absolute path already
let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
let Some(executable) = which(expanded_name, &paths, cwd.as_ref()) else {
return Err(command_not_found(&name_str, call.head, engine_state, stack));
return Err(command_not_found(
&name_str,
call.head,
engine_state,
stack,
&cwd,
));
};
executable
};
@ -371,6 +377,7 @@ pub fn command_not_found(
span: Span,
engine_state: &EngineState,
stack: &mut Stack,
cwd: &AbsolutePath,
) -> ShellError {
// Run the `command_not_found` hook if there is one.
if let Some(hook) = &stack.get_config(engine_state).hooks.command_not_found {
@ -481,12 +488,12 @@ pub fn command_not_found(
}
// If we find a file, it's likely that the user forgot to set permissions
if Path::new(name).is_file() {
if cwd.join(name).is_file() {
return ShellError::ExternalCommand {
label: format!("Command `{name}` not found"),
help: format!("`{name}` refers to a file that is not executable. Did you forget to set execute permissions?"),
span,
};
label: format!("Command `{name}` not found"),
help: format!("`{name}` refers to a file that is not executable. Did you forget to set execute permissions?"),
span,
};
}
// We found nothing useful. Give up and return a generic error message.

View File

@ -68,7 +68,7 @@ fn pre_prompt_hook(code: &str) -> String {
format!(
"$env.config = {{
hooks: {{
pre_prompt: {code}
pre_prompt: [{code}]
}}
}}"
)
@ -78,9 +78,9 @@ fn pre_prompt_hook_code(code: &str) -> String {
format!(
"$env.config = {{
hooks: {{
pre_prompt: {{
pre_prompt: [{{
code: {code}
}}
}}]
}}
}}"
)
@ -90,7 +90,7 @@ fn pre_execution_hook(code: &str) -> String {
format!(
"$env.config = {{
hooks: {{
pre_execution: {code}
pre_execution: [{code}]
}}
}}"
)
@ -100,9 +100,9 @@ fn pre_execution_hook_code(code: &str) -> String {
format!(
"$env.config = {{
hooks: {{
pre_execution: {{
pre_execution: [{{
code: {code}
}}
}}]
}}
}}"
)