From 279c4335737667cbcf640bda799a783d14ad4b2b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 13 Feb 2021 10:52:22 +0000 Subject: sp-extract: Move file extraction Signed-off-by: Daniel Silverstone --- src/bin/cli/mod.rs | 13 ++++++++++++- 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>(filename: P, style: Style) -> Result(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()) -} -- cgit v1.2.1