mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 01:08:51 +02:00
Some cleanups for cd/PWD (#667)
* Some cleanups for cd/PWD * Some cleanups for cd/PWD
This commit is contained in:
@ -2,7 +2,7 @@ use std::path::Path;
|
||||
|
||||
use nu_engine::env::current_dir_str;
|
||||
use nu_engine::CallExt;
|
||||
use nu_path::{canonicalize_with, expand_path};
|
||||
use nu_path::{canonicalize_with, expand_path_with};
|
||||
use nu_protocol::{engine::Command, Example, ShellError, Signature, Span, SyntaxShape, Value};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
@ -82,7 +82,7 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Expand a relative path",
|
||||
example: r"'foo\..\bar' | path expand",
|
||||
result: Some(Value::test_string("bar")),
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -103,7 +103,7 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Expand a relative path",
|
||||
example: "'foo/../bar' | path expand",
|
||||
result: Some(Value::test_string("bar")),
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -123,7 +123,7 @@ fn expand(path: &Path, span: Span, args: &Arguments) -> Value {
|
||||
),
|
||||
}
|
||||
} else {
|
||||
Value::string(expand_path(path).to_string_lossy(), span)
|
||||
Value::string(expand_path_with(path, &args.cwd).to_string_lossy(), span)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,7 @@ impl Command for SubCommand {
|
||||
"Optionally operate by column path",
|
||||
Some('c'),
|
||||
)
|
||||
.optional(
|
||||
"append",
|
||||
SyntaxShape::Filepath,
|
||||
"Path to append to the input",
|
||||
)
|
||||
.optional("append", SyntaxShape::String, "Path to append to the input")
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@ -30,7 +30,7 @@ impl Command for SubCommand {
|
||||
Signature::build("path relative-to")
|
||||
.required(
|
||||
"path",
|
||||
SyntaxShape::Filepath,
|
||||
SyntaxShape::String,
|
||||
"Parent shared with the input path",
|
||||
)
|
||||
.named(
|
||||
@ -116,7 +116,9 @@ path."#
|
||||
fn relative_to(path: &Path, span: Span, args: &Arguments) -> Value {
|
||||
match path.strip_prefix(Path::new(&args.path.item)) {
|
||||
Ok(p) => Value::string(p.to_string_lossy(), span),
|
||||
Err(_) => todo!(),
|
||||
Err(e) => Value::Error {
|
||||
error: ShellError::CantConvert(e.to_string(), "string".into(), span),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user