Skip to main content

chronicle/cli/
note.rs

1use crate::annotate::staging;
2use crate::error::Result;
3
4/// Run `git chronicle note` command.
5pub fn run(text: Option<String>, list: bool, clear: bool) -> Result<()> {
6    let git_dir = find_git_dir()?;
7
8    if clear {
9        staging::clear_staged(&git_dir)?;
10        println!("Staged notes cleared.");
11        return Ok(());
12    }
13
14    if list || text.is_none() {
15        let notes = staging::read_staged(&git_dir)?;
16        if notes.is_empty() {
17            println!("No staged notes.");
18        } else {
19            println!("Staged notes ({}):", notes.len());
20            for note in &notes {
21                println!("  [{}] {}", note.timestamp, note.text);
22            }
23        }
24        return Ok(());
25    }
26
27    if let Some(note_text) = text {
28        staging::append_staged(&git_dir, &note_text)?;
29        let count = staging::read_staged(&git_dir)?.len();
30        println!("Note staged ({count} total). Will be included in next annotation.");
31    }
32
33    Ok(())
34}
35
36use super::util::find_git_dir;