2024-08-24 15:40:44 +02:00
|
|
|
use cuddle_state::Cuddle;
|
|
|
|
use state::{validated_project::Project, ValidatedState};
|
2024-08-23 23:22:35 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
mod cuddle_state;
|
2024-08-24 00:45:16 +02:00
|
|
|
mod plan;
|
|
|
|
mod project;
|
2024-08-24 14:55:26 +02:00
|
|
|
mod schema_validator;
|
|
|
|
mod state;
|
2024-08-23 21:51:42 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
let cuddle = Cuddle::default()
|
2024-08-24 00:45:16 +02:00
|
|
|
.prepare_project()
|
|
|
|
.await?
|
|
|
|
.prepare_plan()
|
2024-08-24 14:55:26 +02:00
|
|
|
.await?
|
|
|
|
.build_state()
|
2024-08-24 00:45:16 +02:00
|
|
|
.await?;
|
2024-08-23 23:21:53 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
Cli::new(cuddle).setup().await?.execute().await?;
|
|
|
|
|
2024-08-23 23:21:53 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
pub struct Cli {
|
|
|
|
cli: clap::Command,
|
|
|
|
cuddle: Cuddle<ValidatedState>,
|
2024-08-24 00:45:16 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
impl Cli {
|
|
|
|
pub fn new(cuddle: Cuddle<ValidatedState>) -> Self {
|
|
|
|
let cli = clap::Command::new("cuddle").subcommand_required(true);
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
Self { cli, cuddle }
|
|
|
|
}
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
pub async fn setup(mut self) -> anyhow::Result<Self> {
|
|
|
|
let s = self
|
|
|
|
.add_default()
|
|
|
|
.await?
|
|
|
|
.add_project_commands()
|
|
|
|
.await?
|
|
|
|
.add_plan_commands()
|
|
|
|
.await?;
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
// TODO: Add global
|
|
|
|
// TODO: Add components
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
Ok(s)
|
|
|
|
}
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
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(())
|
2024-08-24 00:45:16 +02:00
|
|
|
}
|
2024-08-23 23:21:53 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
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)
|
2024-08-24 14:55:26 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
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)
|
|
|
|
}
|
2024-08-24 14:55:26 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
async fn add_plan_commands(mut self) -> anyhow::Result<Self> {
|
|
|
|
if let Some(plan) = self.cuddle.state.plan.as_ref() {
|
|
|
|
// Add plan level commands
|
|
|
|
}
|
2024-08-24 14:55:26 +02:00
|
|
|
|
2024-08-24 15:40:44 +02:00
|
|
|
Ok(self)
|
2024-08-23 21:51:42 +02:00
|
|
|
}
|
2024-08-23 23:21:53 +02:00
|
|
|
}
|