cuddle-v2/crates/cuddle/src/main.rs

96 lines
2.1 KiB
Rust
Raw Normal View History

use cuddle_state::Cuddle;
use state::{validated_project::Project, 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<ValidatedState>,
}
impl Cli {
pub fn new(cuddle: Cuddle<ValidatedState>) -> Self {
let cli = clap::Command::new("cuddle").subcommand_required(true);
Self { cli, cuddle }
}
pub async fn setup(mut self) -> anyhow::Result<Self> {
let s = self
.add_default()
.await?
.add_project_commands()
.await?
.add_plan_commands()
.await?;
// TODO: Add global
// TODO: Add components
Ok(s)
}
pub async fn execute(mut 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");
}
_ => {}
}
Ok(())
}
async fn add_default(mut self) -> anyhow::Result<Self> {
self.cli = self
.cli
.subcommand(clap::Command::new("do").alias("x"))
.subcommand(clap::Command::new("get"));
Ok(self)
}
async fn add_project_commands(mut self) -> anyhow::Result<Self> {
if let Some(project) = self.cuddle.state.project.as_ref() {
// Add project level commands
}
Ok(self)
}
async fn add_plan_commands(mut self) -> anyhow::Result<Self> {
if let Some(plan) = self.cuddle.state.plan.as_ref() {
// Add plan level commands
}
Ok(self)
}
}