summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-30 10:06:39 +0000
committerLars Wirzenius <liw@liw.fi>2021-08-30 10:06:39 +0000
commit4e7e22eeb0622186b3fd470fe3872e4c423a1933 (patch)
treee9f8bff9bd5f93b314f1aa50af4f3a1c422872ac /src
parentcdb691a5c7af52be7a9ad6a318d420b9a8d633a2 (diff)
parent93e471629caac421e1c233fb1ea5b3cc85dbe0ca (diff)
downloadsubplot-4e7e22eeb0622186b3fd470fe3872e4c423a1933.tar.gz
Merge branch 'no-parent-means-curdir' into 'main'
policy: No parent directory means basedir is curdir See merge request subplot/subplot!203
Diffstat (limited to 'src')
-rw-r--r--src/bin/cli/mod.rs2
-rw-r--r--src/policy.rs17
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)
+ }
}