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.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 94c4b53..fabb0f2 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -6,6 +6,7 @@ use anyhow::Result;
use structopt::StructOpt;
use subplot::{resource, DataFile, Document, Style};
+use std::convert::TryFrom;
use std::fs::{write, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
@@ -32,6 +33,7 @@ impl Toplevel {
enum Cmd {
Extract(Extract),
Filter(Filter),
+ Metadata(Metadata),
}
impl Cmd {
@@ -39,6 +41,7 @@ impl Cmd {
match self {
Cmd::Extract(e) => e.run(),
Cmd::Filter(f) => f.run(),
+ Cmd::Metadata(m) => m.run(),
}
}
}
@@ -150,6 +153,34 @@ impl Filter {
}
}
+#[derive(Debug, StructOpt)]
+/// Extract metadata about a document
+///
+/// Load and process a subplot document, extracting various metadata about the
+/// document. This can then render that either as a plain text report for humans,
+/// or as a JSON object for further scripted processing.
+struct Metadata {
+ /// Form that you want the output to take
+ #[structopt(short = "o", default_value = "plain", possible_values=&["plain", "json"])]
+ output_format: cli::OutputFormat,
+
+ /// Input subplot document filename
+ #[structopt(parse(from_os_str))]
+ filename: PathBuf,
+}
+
+impl Metadata {
+ fn run(&self) -> Result<()> {
+ let mut doc = cli::load_document(&self.filename, Style::default())?;
+ let meta = cli::Metadata::try_from(&mut doc)?;
+ match self.output_format {
+ cli::OutputFormat::Plain => meta.write_out(),
+ cli::OutputFormat::Json => println!("{}", serde_json::to_string_pretty(&meta)?),
+ }
+ Ok(())
+ }
+}
+
fn main() {
let args = Toplevel::from_args();
args.resources.handle();