Path migration 1 (#13309)

# Description
Part 1 of replacing `std::path` types with `nu_path` types added in
#13115.
This commit is contained in:
Ian Manske
2024-07-09 09:25:23 +00:00
committed by GitHub
parent 399a7c8836
commit e98b2ceb8c
11 changed files with 51 additions and 54 deletions

View File

@ -60,12 +60,13 @@ impl Command for ConfigEnv {
let (editor_name, editor_args) = get_editor(engine_state, stack, call.head)?;
let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
let cwd = engine_state.cwd(Some(stack))?;
let editor_executable =
crate::which(&editor_name, &paths, &cwd).ok_or(ShellError::ExternalCommand {
let editor_executable = crate::which(&editor_name, &paths, cwd.as_ref()).ok_or(
ShellError::ExternalCommand {
label: format!("`{editor_name}` not found"),
help: "Failed to find the editor executable".into(),
span: call.head,
})?;
},
)?;
let Some(env_path) = engine_state.get_config_path("env-path") else {
return Err(ShellError::GenericError {

View File

@ -64,12 +64,13 @@ impl Command for ConfigNu {
let (editor_name, editor_args) = get_editor(engine_state, stack, call.head)?;
let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
let cwd = engine_state.cwd(Some(stack))?;
let editor_executable =
crate::which(&editor_name, &paths, &cwd).ok_or(ShellError::ExternalCommand {
let editor_executable = crate::which(&editor_name, &paths, cwd.as_ref()).ok_or(
ShellError::ExternalCommand {
label: format!("`{editor_name}` not found"),
help: "Failed to find the editor executable".into(),
span: call.head,
})?;
},
)?;
let Some(config_path) = engine_state.get_config_path("config-path") else {
return Err(ShellError::GenericError {

View File

@ -1,5 +1,6 @@
use nu_cmd_base::util::get_init_cwd;
use nu_engine::command_prelude::*;
use nu_path::AbsolutePathBuf;
use nu_utils::filesystem::{have_permission, PermissionResult};
#[derive(Clone)]
@ -43,7 +44,10 @@ impl Command for Cd {
// If getting PWD failed, default to the initial directory. This way, the
// user can use `cd` to recover PWD to a good state.
let cwd = engine_state.cwd(Some(stack)).unwrap_or(get_init_cwd());
let cwd = engine_state
.cwd(Some(stack))
.map(AbsolutePathBuf::into_std_path_buf)
.unwrap_or(get_init_cwd());
let path_val = {
if let Some(path) = path_val {

View File

@ -1,13 +1,11 @@
use super::PathSubcommandArguments;
use nu_engine::command_prelude::*;
use nu_path::AbsolutePathBuf;
use nu_protocol::engine::StateWorkingSet;
use std::{
io,
path::{Path, PathBuf},
};
use std::{io, path::Path};
struct Arguments {
pwd: PathBuf,
pwd: AbsolutePathBuf,
}
impl PathSubcommandArguments for Arguments {}

View File

@ -39,7 +39,7 @@ On Windows based systems, Nushell will wait for the command to finish and then e
let name: Spanned<String> = call.req(engine_state, stack, 0)?;
let executable = {
let paths = nu_engine::env::path_str(engine_state, stack, call.head)?;
let Some(executable) = crate::which(&name.item, &paths, &cwd) else {
let Some(executable) = crate::which(&name.item, &paths, cwd.as_ref()) else {
return Err(crate::command_not_found(
&name.item,
call.head,

View File

@ -79,7 +79,7 @@ impl Command for External {
// Determine the PATH to be used and then use `which` to find it - though this has no
// 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) else {
let Some(executable) = which(expanded_name, &paths, cwd.as_ref()) else {
return Err(command_not_found(&name_str, call.head, engine_state, stack));
};
executable
@ -228,7 +228,7 @@ pub fn eval_arguments_from_call(
match arg {
// Expand globs passed to run-external
Value::Glob { val, no_expand, .. } if !no_expand => args.extend(
expand_glob(&val, &cwd, expr.span, engine_state.signals())?
expand_glob(&val, cwd.as_ref(), expr.span, engine_state.signals())?
.into_iter()
.map(|s| s.into_spanned(expr.span)),
),

View File

@ -83,7 +83,7 @@ prints out the list properly."#
separator_param,
env_str,
use_grid_icons,
&cwd,
cwd.as_ref(),
)?)
} else {
Ok(PipelineData::empty())
@ -101,7 +101,7 @@ prints out the list properly."#
separator_param,
env_str,
use_grid_icons,
&cwd,
cwd.as_ref(),
)?)
} else {
// dbg!(data);
@ -124,7 +124,7 @@ prints out the list properly."#
separator_param,
env_str,
use_grid_icons,
&cwd,
cwd.as_ref(),
)?)
}
x => {