2024-08-24 15:40:44 +02:00
|
|
|
use cuddle_state::Cuddle;
|
2024-08-25 17:20:12 +02:00
|
|
|
use state::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-25 21:08:34 +02:00
|
|
|
pub async fn setup(mut self) -> anyhow::Result<Self> {
|
|
|
|
let commands = self.get_commands().await?;
|
|
|
|
|
|
|
|
self.cli = self.cli.subcommands(commands);
|
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-25 21:08:34 +02:00
|
|
|
Ok(self)
|
2024-08-24 15:40:44 +02:00
|
|
|
}
|
2024-08-24 00:45:16 +02:00
|
|
|
|
2024-08-25 17:20:12 +02:00
|
|
|
pub async fn execute(self) -> anyhow::Result<()> {
|
2024-08-24 15:40:44 +02:00
|
|
|
match self
|
|
|
|
.cli
|
|
|
|
.get_matches_from(std::env::args())
|
|
|
|
.subcommand()
|
|
|
|
.ok_or(anyhow::anyhow!("failed to find subcommand"))?
|
|
|
|
{
|
2024-08-25 17:20:12 +02:00
|
|
|
("do", _args) => {
|
2024-08-24 15:40:44 +02:00
|
|
|
tracing::debug!("executing do");
|
|
|
|
}
|
2024-08-25 17:20:12 +02:00
|
|
|
("get", _args) => {}
|
2024-08-24 15:40:44 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
2024-08-24 00:45:16 +02:00
|
|
|
}
|
2024-08-23 23:21:53 +02:00
|
|
|
|
2024-08-25 21:08:34 +02:00
|
|
|
async fn get_commands(&self) -> anyhow::Result<Vec<clap::Command>> {
|
|
|
|
Ok(vec![
|
|
|
|
clap::Command::new("do").subcommand_required(true),
|
|
|
|
clap::Command::new("get"),
|
|
|
|
])
|
2024-08-24 14:55:26 +02:00
|
|
|
}
|
|
|
|
|
2024-08-25 21:08:34 +02:00
|
|
|
async fn add_project_commands(&self) -> anyhow::Result<Vec<clap::Command>> {
|
2024-08-25 17:27:31 +02:00
|
|
|
if let Some(_project) = self.cuddle.state.project.as_ref() {
|
2024-08-24 15:40:44 +02:00
|
|
|
// Add project level commands
|
2024-08-25 21:08:34 +02:00
|
|
|
return Ok(vec![]);
|
2024-08-24 15:40:44 +02:00
|
|
|
}
|
|
|
|
|
2024-08-25 21:08:34 +02:00
|
|
|
Ok(Vec::new())
|
2024-08-24 15:40:44 +02:00
|
|
|
}
|
2024-08-24 14:55:26 +02:00
|
|
|
|
2024-08-25 17:20:12 +02:00
|
|
|
async fn add_plan_commands(self) -> anyhow::Result<Self> {
|
2024-08-25 17:27:31 +02:00
|
|
|
if let Some(_plan) = self.cuddle.state.plan.as_ref() {
|
2024-08-24 15:40:44 +02:00
|
|
|
// 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
|
|
|
}
|