summaryrefslogtreecommitdiff
path: root/src/bin/sp-extract.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/sp-extract.rs')
-rw-r--r--src/bin/sp-extract.rs19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/bin/sp-extract.rs b/src/bin/sp-extract.rs
index cdd9fba..86bc15a 100644
--- a/src/bin/sp-extract.rs
+++ b/src/bin/sp-extract.rs
@@ -4,7 +4,9 @@ use std::path::PathBuf;
use structopt::StructOpt;
-use subplot::{DataFile, Document, Style, SubplotError};
+use subplot::Style;
+
+mod cli;
#[derive(Debug, StructOpt)]
#[structopt(name = "sp-meta", about = "Show Subplot document metadata.")]
@@ -24,24 +26,13 @@ struct Opt {
fn main() -> Result<()> {
let opt = Opt::from_args();
- let basedir = subplot::get_basedir_from(&opt.filename)?;
- let style = Style::default();
- let doc = Document::from_file(&basedir, &opt.filename, style)?;
+ let doc = cli::load_document(&opt.filename, Style::default())?;
for filename in opt.embedded {
- let file = get_embedded(&doc, &filename)?;
+ let file = cli::extract_file(&doc, &filename)?;
let output = opt.directory.join(filename);
write(output, file.contents())?;
}
Ok(())
}
-
-fn get_embedded<'a>(doc: &'a Document, filename: &str) -> Result<&'a DataFile> {
- for file in doc.files() {
- if file.filename() == filename {
- return Ok(file);
- }
- }
- Err(SubplotError::EmbeddedFileNotFound(filename.to_owned()).into())
-}