diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-02-13 10:52:22 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-04-09 16:42:49 +0100 |
commit | 279c4335737667cbcf640bda799a783d14ad4b2b (patch) | |
tree | f6d34559e91b4c6e17ee95a93279dcfb146314a9 | |
parent | d11605662b06ab6756404fab006ff91c4a251cae (diff) | |
download | subplot-279c4335737667cbcf640bda799a783d14ad4b2b.tar.gz |
sp-extract: Move file extraction
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/bin/cli/mod.rs | 13 | ||||
-rw-r--r-- | src/bin/sp-extract.rs | 13 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 1bb5ea3..855a066 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -1,7 +1,9 @@ //! CLI Functionality abstractions +#![allow(unused)] + use anyhow::Result; -use subplot::{Document, Style}; +use subplot::{DataFile, Document, Style, SubplotError}; use std::path::Path; @@ -12,3 +14,12 @@ pub fn load_document<P: AsRef<Path>>(filename: P, style: Style) -> Result<Docume Ok(doc) } + +pub fn extract_file<'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()) +} diff --git a/src/bin/sp-extract.rs b/src/bin/sp-extract.rs index 9be159f..86bc15a 100644 --- a/src/bin/sp-extract.rs +++ b/src/bin/sp-extract.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use structopt::StructOpt; -use subplot::{DataFile, Document, Style, SubplotError}; +use subplot::Style; mod cli; @@ -29,19 +29,10 @@ fn main() -> Result<()> { 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()) -} |