From dfa70b348593a9053b2ab7f866ff4ab2bcddfeea Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 24 Oct 2024 20:24:28 +0200 Subject: [PATCH] feat: get only in projects Signed-off-by: kjuulh --- crates/cuddle/src/cli.rs | 4 ++++ crates/cuddle/src/cuddle_state.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/crates/cuddle/src/cli.rs b/crates/cuddle/src/cli.rs index 33a3dea..51a746a 100644 --- a/crates/cuddle/src/cli.rs +++ b/crates/cuddle/src/cli.rs @@ -54,6 +54,10 @@ impl Cli { tracing::debug!("executing do"); } ("get", args) => { + if !self.cuddle.has_project() { + anyhow::bail!("get is not available without a project"); + } + let query = args .get_one::("query") .ok_or(anyhow!("query is required"))?; diff --git a/crates/cuddle/src/cuddle_state.rs b/crates/cuddle/src/cuddle_state.rs index 10b8eeb..460aa9d 100644 --- a/crates/cuddle/src/cuddle_state.rs +++ b/crates/cuddle/src/cuddle_state.rs @@ -66,3 +66,17 @@ impl Cuddle { Ok(Cuddle { state }) } } + +impl Cuddle { + pub fn has_project(&self) -> bool { + if self.state.project.is_some() { + return true; + } + + if self.state.plan.is_some() { + return true; + } + + false + } +}