blob: 855a066cafee988d804639b11fdf9ecdb224275e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
//! CLI Functionality abstractions
#![allow(unused)]
use anyhow::Result;
use subplot::{DataFile, Document, Style, SubplotError};
use std::path::Path;
pub fn load_document<P: AsRef<Path>>(filename: P, style: Style) -> Result<Document> {
let filename = filename.as_ref();
let base_path = subplot::get_basedir_from(filename)?;
let doc = Document::from_file(&base_path, filename, style)?;
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())
}
|