use std::fs;
use anyhow::{bail, Context};
use super::toml_command::Tasks;
pub struct CommandParser {
pub path: String,
}
impl CommandParser {
pub fn parse(&self) -> anyhow::Result<Tasks> {
let contents = fs::read_to_string(self.path.clone())
.context(format!("Failed to read from {}", self.path))?;
let tasks: Tasks = toml::from_str(&contents).context("Invalid TOML data")?;
for task in &tasks.tasks {
if task.command.is_empty() {
bail!("Inalid command");
}
}
Ok(tasks)
}
}