summaryrefslogtreecommitdiff
path: root/src/bin/sp-extract.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-10 07:47:32 +0000
committerLars Wirzenius <liw@liw.fi>2021-04-10 07:47:32 +0000
commit03d0ebf178826319cadfea5717181008e3a22685 (patch)
tree0cec7b189fc477d35d1a83e714cce54c96c394cd /src/bin/sp-extract.rs
parent22719be2c3b13e4dd0463db10023d615a6bde847 (diff)
parentde9ee5afd4ec8d3a4b0835b865d7f10c3bf8bb8e (diff)
downloadsubplot-03d0ebf178826319cadfea5717181008e3a22685.tar.gz
Merge branch 'single-binary' into 'main'
Refactor into subplot binary Closes #164 See merge request larswirzenius/subplot!136
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())
-}