use cuddle_state::Cuddle; use state::ValidatedState; mod cuddle_state; mod plan; mod project; mod schema_validator; mod state; #[tokio::main] async fn main() -> anyhow::Result<()> { dotenv::dotenv().ok(); tracing_subscriber::fmt::init(); let cuddle = Cuddle::default() .prepare_project() .await? .prepare_plan() .await? .build_state() .await?; Cli::new(cuddle).setup().await?.execute().await?; Ok(()) } pub struct Cli { cli: clap::Command, cuddle: Cuddle, } impl Cli { pub fn new(cuddle: Cuddle) -> Self { let cli = clap::Command::new("cuddle").subcommand_required(true); Self { cli, cuddle } } pub async fn setup(mut self) -> anyhow::Result { let commands = self.get_commands().await?; self.cli = self.cli.subcommands(commands); // TODO: Add global // TODO: Add components Ok(self) } pub async fn execute(self) -> anyhow::Result<()> { match self .cli .get_matches_from(std::env::args()) .subcommand() .ok_or(anyhow::anyhow!("failed to find subcommand"))? { ("do", _args) => { tracing::debug!("executing do"); } ("get", _args) => {} _ => {} } Ok(()) } async fn get_commands(&self) -> anyhow::Result> { Ok(vec![ clap::Command::new("do").subcommand_required(true), clap::Command::new("get"), ]) } async fn add_project_commands(&self) -> anyhow::Result> { if let Some(_project) = self.cuddle.state.project.as_ref() { // Add project level commands return Ok(vec![]); } Ok(Vec::new()) } async fn add_plan_commands(self) -> anyhow::Result { if let Some(_plan) = self.cuddle.state.plan.as_ref() { // Add plan level commands } Ok(self) } }