diff --git a/crates/onyx-cli/src/commands/group.rs b/crates/onyx-cli/src/commands/group.rs index 5b64661..d819dfe 100644 --- a/crates/onyx-cli/src/commands/group.rs +++ b/crates/onyx-cli/src/commands/group.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use crate::output; use crate::commands::get_repository; -pub fn enable(list_name: String, workspace: Option) -> Result<()> { +fn set_grouping(list_name: String, workspace: Option, enabled: bool) -> Result<()> { let (mut repo, _workspace_name) = get_repository(workspace)?; let lists = repo.get_lists() @@ -12,28 +12,20 @@ pub fn enable(list_name: String, workspace: Option) -> Result<()> { .find(|l| l.title == list_name) .ok_or_else(|| anyhow::anyhow!("List '{}' not found", list_name))?; - repo.set_group_by_date(list.id, true) - .context("Failed to enable grouping")?; + let action = if enabled { "enable" } else { "disable" }; + repo.set_group_by_date(list.id, enabled) + .context(format!("Failed to {} grouping", action))?; - output::success(&format!("Enabled group-by-date for list \"{}\"", list_name)); + let past = if enabled { "Enabled" } else { "Disabled" }; + output::success(&format!("{} group-by-date for list \"{}\"", past, list_name)); Ok(()) } +pub fn enable(list_name: String, workspace: Option) -> Result<()> { + set_grouping(list_name, workspace, true) +} + pub fn disable(list_name: String, workspace: Option) -> Result<()> { - let (mut repo, _workspace_name) = get_repository(workspace)?; - - let lists = repo.get_lists() - .context("Failed to get lists")?; - - let list = lists.iter() - .find(|l| l.title == list_name) - .ok_or_else(|| anyhow::anyhow!("List '{}' not found", list_name))?; - - repo.set_group_by_date(list.id, false) - .context("Failed to disable grouping")?; - - output::success(&format!("Disabled group-by-date for list \"{}\"", list_name)); - - Ok(()) + set_grouping(list_name, workspace, false) }