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 /src/bin/cli/mod.rs | |
parent | d11605662b06ab6756404fab006ff91c4a251cae (diff) | |
download | subplot-279c4335737667cbcf640bda799a783d14ad4b2b.tar.gz |
sp-extract: Move file extraction
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/bin/cli/mod.rs')
-rw-r--r-- | src/bin/cli/mod.rs | 13 |
1 files changed, 12 insertions, 1 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()) +} |