feat: add command get for doing queries

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-08-25 22:13:50 +02:00
parent 23d68caf71
commit 02dd805db4
7 changed files with 246 additions and 67 deletions

View File

@@ -1,6 +1,7 @@
use cli::Cli;
use cuddle_state::Cuddle;
use state::ValidatedState;
mod cli;
mod cuddle_state;
mod plan;
mod project;
@@ -24,68 +25,3 @@ async fn main() -> anyhow::Result<()> {
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 commands = self.get_commands().await?;
self.cli = self.cli.subcommands(commands);
// TODO: Add global
// TODO: Add components
Ok(self)
}
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 get_commands(&self) -> anyhow::Result<Vec<clap::Command>> {
Ok(vec![
clap::Command::new("do").subcommand_required(true),
clap::Command::new("get"),
])
}
async fn add_project_commands(&self) -> anyhow::Result<Vec<clap::Command>> {
if let Some(_project) = self.cuddle.state.project.as_ref() {
// Add project level commands
return Ok(vec![]);
}
Ok(Vec::new())
}
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)
}
}