Skip to main content

update_checkbox_task_status

Function update_checkbox_task_status 

Source
pub fn update_checkbox_task_status(
    contents: &str,
    task_id: &str,
    new_status: TaskStatus,
) -> Result<String, String>
Expand description

Update the status marker of a checkbox-formatted task in the given file contents.

This prefers an explicit numeric task label at the start of a checkbox item’s text (e.g. 1.1 First) and falls back to interpreting task_id as a 1-based index of checkbox items when no explicit label matches. Maps TaskStatus to checkbox markers: Pending -> [ ], InProgress -> [~], Complete -> [x].

Returns Ok(String) with the full updated file content (always ending with a trailing newline), or Err(String) if the requested task cannot be found or if Shelved is requested (not supported for checkbox-only tasks).

§Examples

use ito_domain::tasks::{TaskStatus, update_checkbox_task_status};
let contents = "- [ ] 1.1 First task\n- [ ] Second task\n";
let updated = update_checkbox_task_status(contents, "1.1", TaskStatus::Complete).unwrap();
assert!(updated.contains("- [x] 1.1 First task"));