summaryrefslogtreecommitdiff
path: root/src/bin/subplot.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-05-02 16:31:49 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-05-02 16:31:49 +0100
commitbc9c81a84f8b8ba33098d12104c39b171deb649e (patch)
tree3c42e4e605a41ea34bae90e9c3d7a5efb027c751 /src/bin/subplot.rs
parent3976034a4b99a750946d2f5242158db2fef33d35 (diff)
downloadsubplot-bc9c81a84f8b8ba33098d12104c39b171deb649e.tar.gz
resources: Use new path checking order
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/bin/subplot.rs')
-rw-r--r--src/bin/subplot.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 4a650ee..e2a79d8 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -34,6 +34,11 @@ impl Toplevel {
fn run(&self) -> Result<()> {
self.command.run()
}
+
+ fn handle_resources(&self) {
+ let doc_path = self.command.doc_path();
+ self.resources.handle(doc_path);
+ }
}
#[derive(Debug, StructOpt)]
@@ -55,6 +60,16 @@ impl Cmd {
Cmd::Codegen(c) => c.run(),
}
}
+
+ fn doc_path(&self) -> Option<&Path> {
+ match self {
+ Cmd::Extract(e) => e.doc_path(),
+ Cmd::Filter(f) => f.doc_path(),
+ Cmd::Metadata(m) => m.doc_path(),
+ Cmd::Docgen(d) => d.doc_path(),
+ Cmd::Codegen(c) => c.doc_path(),
+ }
+ }
}
fn long_version() -> Result<String> {
@@ -114,6 +129,10 @@ struct Extract {
}
impl Extract {
+ fn doc_path(&self) -> Option<&Path> {
+ self.filename.parent()
+ }
+
fn run(&self) -> Result<()> {
let doc = cli::load_document(&self.filename, Style::default())?;
@@ -164,6 +183,13 @@ struct Filter {
}
impl Filter {
+ fn doc_path(&self) -> Option<&Path> {
+ self.input
+ .as_ref()
+ .map(PathBuf::as_path)
+ .and_then(Path::parent)
+ }
+
fn run(&self) -> Result<()> {
let mut buffer = String::new();
if let Some(filename) = &self.input {
@@ -208,6 +234,10 @@ struct Metadata {
}
impl Metadata {
+ fn doc_path(&self) -> Option<&Path> {
+ self.filename.parent()
+ }
+
fn run(&self) -> Result<()> {
let mut doc = cli::load_document(&self.filename, Style::default())?;
let meta = cli::Metadata::try_from(&mut doc)?;
@@ -238,6 +268,10 @@ struct Docgen {
}
impl Docgen {
+ fn doc_path(&self) -> Option<&Path> {
+ self.input.parent()
+ }
+
fn run(&self) -> Result<()> {
let mut style = Style::default();
if self.output.extension() == Some(&OsString::from("pdf")) {
@@ -334,6 +368,10 @@ struct Codegen {
}
impl Codegen {
+ fn doc_path(&self) -> Option<&Path> {
+ self.filename.parent()
+ }
+
fn run(&self) -> Result<()> {
let mut doc = cli::load_document(&self.filename, Style::default())?;
doc.lint()?;
@@ -373,7 +411,7 @@ fn main() {
let argparser = argparser.long_version(version.as_str());
let args = argparser.get_matches();
let args = Toplevel::from_clap(&args);
- args.resources.handle();
+ args.handle_resources();
match args.run() {
Ok(_) => {}
Err(e) => {