mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
if path to ls given that does not exist, report the error.
This commit is contained in:
parent
1d0ed7e957
commit
3256b7adb3
1 changed files with 22 additions and 1 deletions
|
@ -82,11 +82,32 @@ impl Shell for ValueShell {
|
||||||
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let mut full_path = PathBuf::from(self.path());
|
let mut full_path = PathBuf::from(self.path());
|
||||||
|
|
||||||
match &args.nth(0) {
|
let target = args.nth(0);
|
||||||
|
|
||||||
|
match target {
|
||||||
Some(value) => full_path.push(Path::new(&value.as_path()?)),
|
Some(value) => full_path.push(Path::new(&value.as_path()?)),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut value_system = ValueStructure::new();
|
||||||
|
value_system.walk_decorate(&self.value)?;
|
||||||
|
|
||||||
|
if !value_system.exists(&full_path) {
|
||||||
|
if let Some(target) = target {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Can not list entries inside",
|
||||||
|
"No such path exists",
|
||||||
|
target.span(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Can not list entries inside",
|
||||||
|
"No such path exists",
|
||||||
|
args.call_info.name_span,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.members_under(full_path.as_path())
|
.members_under(full_path.as_path())
|
||||||
.map(|x| ReturnSuccess::value(x))
|
.map(|x| ReturnSuccess::value(x))
|
||||||
|
|
Loading…
Reference in a new issue