cuddle-v2/crates/cuddle/src/main.rs
kjuulh b3aedfb411
chore: fix warnings
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-08-25 17:27:31 +02:00

97 lines
2.1 KiB
Rust

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<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(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(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 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(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(self) -> anyhow::Result<Self> {
if let Some(_plan) = self.cuddle.state.plan.as_ref() {
// Add plan level commands
}
Ok(self)
}
}