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::output;
|
||||||
use crate::commands::get_repository;
|
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 (mut repo, _workspace_name) = get_repository(workspace)?;
|
||||||
|
|
||||||
let lists = repo.get_lists()
|
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)
|
.find(|l| l.title == list_name)
|
||||||
.ok_or_else(|| anyhow::anyhow!("List '{}' not found", list_name))?;
|
.ok_or_else(|| anyhow::anyhow!("List '{}' not found", list_name))?;
|
||||||
|
|
||||||
repo.set_group_by_date(list.id, true)
|
let action = if enabled { "enable" } else { "disable" };
|
||||||
.context("Failed to enable grouping")?;
|
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(())
|
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<()> {
|
pub fn disable(list_name: String, workspace: Option<String>) -> Result<()> {
|
||||||
let (mut repo, _workspace_name) = get_repository(workspace)?;
|
set_grouping(list_name, workspace, false)
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue