refactor: deduplicate CLI group enable/disable into single function
The enable() and disable() functions were identical except for the boolean parameter and output message. Extract shared set_grouping() helper. https://claude.ai/code/session_013ooJht2HrZUTXgNJFU79cV
This commit is contained in:
parent
a313a6e270
commit
1ad6fddda6
|
|
@ -2,7 +2,7 @@ use anyhow::{Context, Result};
|
|||
use crate::output;
|
||||
use crate::commands::get_repository;
|
||||
|
||||
pub fn enable(list_name: String, workspace: Option<String>) -> Result<()> {
|
||||
fn set_grouping(list_name: String, workspace: Option<String>, 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<String>) -> 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<String>) -> Result<()> {
|
||||
set_grouping(list_name, workspace, true)
|
||||
}
|
||||
|
||||
pub fn disable(list_name: String, workspace: Option<String>) -> 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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue