Skip to main content

kimun_notes/cli/commands/
notes.rs

1// tui/src/cli/commands/notes.rs
2use color_eyre::eyre::Result;
3use kimun_core::NoteVault;
4use crate::cli::output::{OutputFormat, format_note_entries_text_with_journal};
5use crate::cli::json_output::format_notes_as_json;
6
7pub async fn run(
8    vault: &NoteVault,
9    path_filter: Option<&str>,
10    format: OutputFormat,
11    workspace_name: &str,
12    _include_backlinks: bool,
13) -> Result<()> {
14    let mut results = vault.get_all_notes().await?;
15
16    // Apply path filter if provided
17    if let Some(prefix) = path_filter {
18        results.retain(|(entry_data, _)| {
19            entry_data.path.to_string().starts_with(prefix)
20        });
21    }
22
23    match format {
24        OutputFormat::Text => {
25            let output = format_note_entries_text_with_journal(vault, &results);
26            print!("{}", output);
27        }
28        OutputFormat::Paths => {
29            for (entry_data, _) in &results {
30                println!("{}", entry_data.path.to_bare_string());
31            }
32        }
33        OutputFormat::Json => {
34            let json_output = format_notes_as_json(
35                vault,
36                &results,
37                workspace_name,
38                None,
39                true, // is_listing
40            ).await
41            .map_err(|e| color_eyre::eyre::eyre!("JSON formatting error: {}", e))?;
42            print!("{}", json_output);
43        }
44    }
45
46    Ok(())
47}