party_run/parser/
command_parser.rs1use std::fs;
3
4use anyhow::{bail, Context};
5
6use super::toml_command::Tasks;
7
8pub struct CommandParser {
10 pub path: String,
12}
13
14impl CommandParser {
15 pub fn parse(&self) -> anyhow::Result<Tasks> {
18 let contents = fs::read_to_string(self.path.clone())
19 .context(format!("Failed to read from {}", self.path))?;
20
21 let tasks: Tasks = toml::from_str(&contents).context("Invalid TOML data")?;
22
23 for task in &tasks.tasks {
24 if task.command.is_empty() {
25 bail!("Inalid command");
26 }
27 }
28
29 Ok(tasks)
30 }
31}