use std::path::PathBuf;
use anyhow::{anyhow, Result};
use crate::utils;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum SrcType {
File,
}
pub struct TaskSrc {
pub data: String,
pub kind: SrcType,
pub location: String,
}
impl TaskSrc {
pub fn from_file(file_paths: Vec<PathBuf>) -> Result<Vec<TaskSrc>> {
let mut payload: Vec<TaskSrc> = vec![];
for file in file_paths {
let file_content = utils::get_file_content(&file)?;
for line in file_content.lines().filter(|l| !l.is_empty()) {
if let Some(location) = file.as_path().to_str() {
payload.push(TaskSrc {
data: line.to_string(),
kind: SrcType::File,
location: String::from(location),
})
} else {
return Err(anyhow!("Failed to coerce path into a string: {:?}", file));
}
}
}
Ok(payload)
}
}