summaryrefslogtreecommitdiff
path: root/src/bin/cli/mod.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/cli/mod.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/cli/mod.rs')
-rw-r--r--src/bin/cli/mod.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs
index 84bda10..4f172e2 100644
--- a/src/bin/cli/mod.rs
+++ b/src/bin/cli/mod.rs
@@ -4,10 +4,10 @@
use anyhow::Result;
use serde::Serialize;
-use std::convert::TryFrom;
use std::fmt::Debug;
use std::path::Path;
use std::str::FromStr;
+use std::{collections::HashMap, convert::TryFrom};
use subplot::{DataFile, Document, Style, SubplotError};
use tracing::{event, instrument, Level};
@@ -25,7 +25,7 @@ pub struct Metadata {
sources: Vec<String>,
title: String,
binding_files: Vec<String>,
- function_files: Vec<String>,
+ impls: HashMap<String, Vec<String>>,
bibliographies: Vec<String>,
scenarios: Vec<String>,
files: Vec<String>,
@@ -35,7 +35,7 @@ impl TryFrom<&mut Document> for Metadata {
type Error = subplot::SubplotError;
fn try_from(doc: &mut Document) -> std::result::Result<Self, Self::Error> {
let mut sources: Vec<_> = doc
- .sources()
+ .sources(None)
.into_iter()
.map(|p| filename(Some(&p)))
.collect();
@@ -48,13 +48,21 @@ impl TryFrom<&mut Document> for Metadata {
.map(|p| filename(Some(p)))
.collect();
binding_files.sort_unstable();
- let mut function_files: Vec<_> = doc
+ let impls: HashMap<_, _> = doc
.meta()
- .functions_filenames()
- .into_iter()
- .map(|p| filename(Some(p)))
+ .templates()
+ .map(|template| {
+ let mut filenames: Vec<_> = doc
+ .meta()
+ .document_impl(template)
+ .unwrap()
+ .functions_filenames()
+ .map(|p| filename(Some(p)))
+ .collect();
+ filenames.sort_unstable();
+ (template.to_string(), filenames)
+ })
.collect();
- function_files.sort_unstable();
let mut bibliographies: Vec<_> = doc
.meta()
.bibliographies()
@@ -78,7 +86,7 @@ impl TryFrom<&mut Document> for Metadata {
sources,
title,
binding_files,
- function_files,
+ impls,
bibliographies,
scenarios,
files,
@@ -95,7 +103,9 @@ impl Metadata {
Self::write_list(&self.sources, "source");
println!("title: {}", self.title);
Self::write_list(&self.binding_files, "bindings");
- Self::write_list(&self.function_files, "functions");
+ for (template, filenames) in self.impls.iter() {
+ Self::write_list(filenames, &format!("functions[{}]", template));
+ }
Self::write_list(&self.bibliographies, "bibliography");
Self::write_list(&self.files, "file");
Self::write_list(&self.scenarios, "scenario");