summaryrefslogtreecommitdiff
path: root/src/bin/subplot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/subplot.rs')
-rw-r--r--src/bin/subplot.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 6d098f3..6a41968 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -165,7 +165,7 @@ impl Extract {
}
fn run(&self) -> Result<()> {
- let doc = load_linted_doc(&self.filename, Style::default(), &None, self.merciful)?;
+ let doc = load_linted_doc(&self.filename, Style::default(), None, self.merciful)?;
let files: Vec<&DataFile> = if self.embedded.is_empty() {
doc.files()
@@ -271,7 +271,7 @@ impl Metadata {
}
fn run(&self) -> Result<()> {
- let mut doc = load_linted_doc(&self.filename, Style::default(), &None, self.merciful)?;
+ let mut doc = load_linted_doc(&self.filename, Style::default(), None, self.merciful)?;
let meta = cli::Metadata::try_from(&mut doc)?;
match self.output_format {
cli::OutputFormat::Plain => meta.write_out(),
@@ -320,7 +320,7 @@ impl Docgen {
trace!("PDF output chosen");
style.typeset_links_as_notes();
}
- let mut doc = load_linted_doc(&self.input, style, &self.template, self.merciful)?;
+ let mut doc = load_linted_doc(&self.input, style, self.template.as_deref(), self.merciful)?;
let mut pandoc = pandoc::new();
// Metadata date from command line or file mtime. However, we
@@ -340,7 +340,7 @@ impl Docgen {
pandoc.add_option(pandoc::PandocOption::Standalone);
pandoc.add_option(pandoc::PandocOption::NumberSections);
- if Self::need_output(&mut doc, &self.template, &self.output) {
+ if Self::need_output(&mut doc, self.template.as_deref(), &self.output) {
doc.typeset();
pandoc.set_input_format(pandoc::InputFormat::Json, vec![]);
pandoc.set_input(pandoc::InputKind::Pipe(doc.ast()?));
@@ -366,7 +366,7 @@ impl Docgen {
time.format(DATE_FORMAT).unwrap()
}
- fn need_output(doc: &mut subplot::Document, template: &Option<String>, output: &Path) -> bool {
+ fn need_output(doc: &mut subplot::Document, template: Option<&str>, output: &Path) -> bool {
let output = match Self::mtime(output) {
Err(_) => return true,
Ok(ts) => ts,
@@ -453,7 +453,7 @@ impl Codegen {
fn load_linted_doc(
filename: &Path,
style: Style,
- template: &Option<String>,
+ template: Option<&str>,
merciful: bool,
) -> Result<Document, SubplotError> {
let mut doc = load_document(filename, style, None)?;
@@ -463,11 +463,16 @@ fn load_linted_doc(
let meta = doc.meta();
trace!("Looking for template, meta={:#?}", meta);
- let template = template
- .as_deref()
- .map(Ok)
- .unwrap_or_else(|| doc.template())
- .unwrap_or("");
+
+ // Get template as given to use (from command line), or from
+ // document, or else default to the empty string.
+ let template = if let Some(t) = template {
+ t
+ } else if let Ok(t) = doc.template() {
+ t
+ } else {
+ ""
+ };
let template = template.to_string();
trace!("Template: {:#?}", template);
doc.check_named_files_exist(&template)?;