use anyhow::{Result, bail};
use clap::Parser;
use crate::store::Store;
#[derive(Debug, Parser)]
#[command(help_template = crate::HELP_TEMPLATE_OPT_ARG, styles = crate::STYLES)]
pub struct CommandNew {
task: String,
}
impl CommandNew {
pub fn execute(self) -> Result<()> {
if self.task.is_empty() {
bail!("task name cannot be empty");
}
let store = Store::new()?;
let tasks = store.get_tasks()?;
if tasks.contains(&self.task) {
bail!("task {} already exists", self.task);
}
store.add_task(self.task.clone())?;
Ok(())
}
}