From 23d68caf719b121b646537543f9b4b32e523980f Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 25 Aug 2024 21:08:34 +0200 Subject: [PATCH] chore: cleanup before get Signed-off-by: kjuulh --- crates/cuddle/src/main.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/cuddle/src/main.rs b/crates/cuddle/src/main.rs index 167ab4a..70adf89 100644 --- a/crates/cuddle/src/main.rs +++ b/crates/cuddle/src/main.rs @@ -37,19 +37,15 @@ impl Cli { Self { cli, cuddle } } - pub async fn setup(self) -> anyhow::Result { - let s = self - .add_default() - .await? - .add_project_commands() - .await? - .add_plan_commands() - .await?; + 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(s) + Ok(self) } pub async fn execute(self) -> anyhow::Result<()> { @@ -69,21 +65,20 @@ impl Cli { Ok(()) } - async fn add_default(mut self) -> anyhow::Result { - self.cli = self - .cli - .subcommand(clap::Command::new("do").alias("x")) - .subcommand(clap::Command::new("get")); - - Ok(self) + 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 { + 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(self) + Ok(Vec::new()) } async fn add_plan_commands(self) -> anyhow::Result {