From a449d2c005727693728d984de1ff1c70877dd5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Tue, 3 Sep 2019 03:49:20 -0500 Subject: [PATCH] If path to cd given. Report the error with the path given. --- src/shell/value_shell.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/shell/value_shell.rs b/src/shell/value_shell.rs index 76be024dd4..1f6d6c7963 100644 --- a/src/shell/value_shell.rs +++ b/src/shell/value_shell.rs @@ -82,7 +82,9 @@ impl Shell for ValueShell { } fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { - let path = match args.nth(0) { + let destination = args.nth(0); + + let path = match destination { None => "/".to_string(), Some(v) => { let target = v.as_path()?; @@ -108,6 +110,14 @@ impl Shell for ValueShell { value_system.walk_decorate(&self.value)?; if !value_system.exists(&PathBuf::from(&path)) { + if let Some(destination) = destination { + return Err(ShellError::labeled_error( + "Can not change to path inside", + "No such path exists", + destination.span(), + )); + } + return Err(ShellError::labeled_error( "Can not change to path inside", "No such path exists",