diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-08-30 10:15:28 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-08-30 10:15:28 +0100 |
commit | 93e471629caac421e1c233fb1ea5b3cc85dbe0ca (patch) | |
tree | c1ce66e4d6afbcbc8d6c676bb303a9ce38c9e3ce /src | |
parent | 08063f6d7241817cf1a04367be25b0c43202c15b (diff) | |
download | subplot-93e471629caac421e1c233fb1ea5b3cc85dbe0ca.tar.gz |
policy: No parent directory means basedir is curdir
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/cli/mod.rs | 2 | ||||
-rw-r--r-- | src/policy.rs | 17 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 6d643ba..0008a16 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -12,7 +12,7 @@ use std::str::FromStr; pub fn load_document<P: AsRef<Path>>(filename: P, style: Style) -> Result<Document> { let filename = filename.as_ref(); - let base_path = subplot::get_basedir_from(filename)?; + let base_path = subplot::get_basedir_from(filename); let doc = Document::from_file(&base_path, filename, style)?; Ok(doc) diff --git a/src/policy.rs b/src/policy.rs index 2d5bda6..e24bf8f 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -1,15 +1,16 @@ -use crate::{Result, SubplotError}; - -use std::path::{Path, PathBuf}; +use std::path::{Component, Path, PathBuf}; /// Get the base directory given the name of the markdown file. /// /// All relative filename, such as bindings files, are resolved /// against the base directory. -pub fn get_basedir_from(filename: &Path) -> Result<PathBuf> { - let dirname = match filename.parent() { - None => return Err(SubplotError::BasedirError(filename.to_path_buf())), +pub fn get_basedir_from(filename: &Path) -> PathBuf { + match filename.parent() { + None => { + let p = Component::CurDir; + let p: &Path = p.as_ref(); + p.to_path_buf() + } Some(x) => x.to_path_buf(), - }; - Ok(dirname) + } } |