summaryrefslogtreecommitdiffstats
path: root/src/context.rs
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2021-03-27 16:46:05 +0100
committerGitHub <noreply@github.com>2021-03-27 11:46:05 -0400
commitcf68f546113eba7e9f84775c302d6d2f880a09d5 (patch)
tree1afdb46e9414256f6dd721565ae27540c435ab37 /src/context.rs
parentc8a787475ca81e4df738cc6180e2b15600bc7f42 (diff)
fix(context): remove unwrap when pwd is unavailable (#2520)
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/context.rs b/src/context.rs
index 7abea681b..8fd0f03d8 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -66,7 +66,10 @@ impl<'a> Context<'a> {
let path = arguments
.value_of("path")
.map(PathBuf::from)
- .unwrap_or_else(|| env::current_dir().expect("Unable to identify current directory"));
+ .or_else(|| env::current_dir().ok())
+ .or_else(|| env::var("PWD").map(PathBuf::from).ok())
+ .or_else(|| arguments.value_of("logical_path").map(PathBuf::from))
+ .unwrap_or_default();
// Retrive the "logical directory".
// If the path argument is not set fall back to the PWD env variable set by many shells
@@ -74,12 +77,8 @@ impl<'a> Context<'a> {
let logical_path = arguments
.value_of("logical_path")
.map(PathBuf::from)
- .unwrap_or_else(|| {
- env::var("PWD").map(PathBuf::from).unwrap_or_else(|err| {
- log::debug!("Unable to get path from $PWD: {}", err);
- path.clone()
- })
- });
+ .or_else(|| env::var("PWD").map(PathBuf::from).ok())
+ .unwrap_or_else(|| path.clone());
Context::new_with_shell_and_path(arguments, shell, path, logical_path)
}