summaryrefslogtreecommitdiff
path: root/src/bin/subplot.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-10-19 19:30:37 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-11-19 20:18:50 +0000
commit5a92266170ae9879b0651e6074e538a4de0a214c (patch)
treed5ecb647701534d6374f441f2c790bfdd2dca848 /src/bin/subplot.rs
parent572d3097770cd8e5cd22d7767c1d18e0d50b9a90 (diff)
downloadsubplot-5a92266170ae9879b0651e6074e538a4de0a214c.tar.gz
various: Rework document to support multiple implementations
In order to eventually shift the document metadata to support more than one template defined for the document this reworks all the internal APIs to expect templates, and also the external CLI to be able to provide it. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/bin/subplot.rs')
-rw-r--r--src/bin/subplot.rs38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 8d4a660..08c4713 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -281,6 +281,12 @@ impl Metadata {
///
/// Process a subplot document and typeset it using Pandoc.
struct Docgen {
+ /// The template to use from the document.
+ ///
+ /// If not specified, subplot will try and find a unique template name from the document
+ #[structopt(name = "TEMPLATE", long = "--template", short = "-t")]
+ template: Option<String>,
+
// Input Subplot document
#[structopt(parse(from_os_str))]
input: PathBuf,
@@ -314,7 +320,13 @@ impl Docgen {
event!(Level::TRACE, "Doc linted ok");
let meta = doc.meta();
event!(Level::TRACE, ?meta, "Looking for template");
- let template = meta.template_name().unwrap_or("").to_string();
+ let template = self
+ .template
+ .as_deref()
+ .map(Ok)
+ .unwrap_or_else(|| doc.template())
+ .unwrap_or("");
+ let template = template.to_string();
event!(Level::TRACE, ?template);
if !doc.check_named_files_exist(&template)? || !doc.check_matched_steps_have_impl(&template)
{
@@ -339,7 +351,7 @@ impl Docgen {
pandoc.add_option(pandoc::PandocOption::Standalone);
pandoc.add_option(pandoc::PandocOption::NumberSections);
- if Self::need_output(&mut doc, &self.output) {
+ if Self::need_output(&mut doc, &template, &self.output) {
doc.typeset();
pandoc.set_input_format(pandoc::InputFormat::Json, vec![]);
pandoc.set_input(pandoc::InputKind::Pipe(doc.ast()?));
@@ -362,13 +374,13 @@ impl Docgen {
dt.format("%Y-%m-%d %H:%M").to_string()
}
- fn need_output(doc: &mut subplot::Document, output: &Path) -> bool {
+ fn need_output(doc: &mut subplot::Document, template: &str, output: &Path) -> bool {
let output = match Self::mtime(output) {
Err(_) => return true,
Ok(ts) => ts,
};
- for filename in doc.sources() {
+ for filename in doc.sources(Some(template)) {
let source = match Self::mtime(&filename) {
Err(_) => return true,
Ok(ts) => ts,
@@ -387,6 +399,12 @@ impl Docgen {
/// This reads a subplot document, extracts the scenarios, and writes out a test
/// program capable of running the scenarios in the subplot document.
struct Codegen {
+ /// The template to use from the document.
+ ///
+ /// If not specified, subplot will try and find a unique template name from the document
+ #[structopt(name = "TEMPLATE", long = "--template", short = "-t")]
+ template: Option<String>,
+
/// Input filename.
#[structopt(parse(from_os_str))]
filename: PathBuf,
@@ -414,13 +432,19 @@ impl Codegen {
let span = span!(Level::TRACE, "codegen");
let _enter = span.enter();
- let output = codegen(&self.filename, &self.output)?;
+ let output = codegen(&self.filename, &self.output, self.template.as_deref())?;
if self.run {
- let run = match output.spec.run() {
+ let spec = output
+ .doc
+ .meta()
+ .document_impl(&output.template)
+ .unwrap()
+ .spec();
+ let run = match spec.run() {
None => {
eprintln!(
"Template {} does not specify how to run suites",
- output.spec.template_filename().display()
+ spec.template_filename().display()
);
std::process::exit(1);
}