diff --git a/src/cli/commands/list.rs b/src/cli/commands/list.rs index 65b7bf3..e3adb39 100644 --- a/src/cli/commands/list.rs +++ b/src/cli/commands/list.rs @@ -980,59 +980,6 @@ pub fn print_list_notes_json(result: &NoteListResult, elapsed_ms: u64, fields: O } } -pub fn print_list_notes_jsonl(result: &NoteListResult) { - for note in &result.notes { - let json_row = NoteListRowJson::from(note); - match serde_json::to_string(&json_row) { - Ok(json) => println!("{json}"), - Err(e) => eprintln!("Error serializing to JSON: {e}"), - } - } -} - -/// Escape a field for RFC 4180 CSV: quote fields containing commas, quotes, or newlines. -fn csv_escape(field: &str) -> String { - if field.contains(',') || field.contains('"') || field.contains('\n') || field.contains('\r') { - let escaped = field.replace('"', "\"\""); - format!("\"{escaped}\"") - } else { - field.to_string() - } -} - -pub fn print_list_notes_csv(result: &NoteListResult) { - println!( - "id,gitlab_id,author_username,body,note_type,is_system,created_at,updated_at,position_new_path,position_new_line,noteable_type,parent_iid,project_path" - ); - for note in &result.notes { - let body = note.body.as_deref().unwrap_or(""); - let note_type = note.note_type.as_deref().unwrap_or(""); - let path = note.position_new_path.as_deref().unwrap_or(""); - let line = note - .position_new_line - .map_or(String::new(), |l| l.to_string()); - let noteable = note.noteable_type.as_deref().unwrap_or(""); - let parent_iid = note.parent_iid.map_or(String::new(), |i| i.to_string()); - - println!( - "{},{},{},{},{},{},{},{},{},{},{},{},{}", - note.id, - note.gitlab_id, - csv_escape(¬e.author_username), - csv_escape(body), - csv_escape(note_type), - note.is_system, - note.created_at, - note.updated_at, - csv_escape(path), - line, - csv_escape(noteable), - parent_iid, - csv_escape(¬e.project_path), - ); - } -} - // --------------------------------------------------------------------------- // Note query layer // --------------------------------------------------------------------------- diff --git a/src/cli/commands/list_tests.rs b/src/cli/commands/list_tests.rs index 3087f62..19775cd 100644 --- a/src/cli/commands/list_tests.rs +++ b/src/cli/commands/list_tests.rs @@ -1269,60 +1269,6 @@ fn test_truncate_note_body() { assert!(result.ends_with("...")); } -#[test] -fn test_csv_escape_basic() { - assert_eq!(csv_escape("simple"), "simple"); - assert_eq!(csv_escape("has,comma"), "\"has,comma\""); - assert_eq!(csv_escape("has\"quote"), "\"has\"\"quote\""); - assert_eq!(csv_escape("has\nnewline"), "\"has\nnewline\""); -} - -#[test] -fn test_csv_output_basic() { - let result = NoteListResult { - notes: vec![NoteListRow { - id: 1, - gitlab_id: 100, - author_username: "alice".to_string(), - body: Some("Hello, world".to_string()), - note_type: Some("DiffNote".to_string()), - is_system: false, - created_at: 1_000_000, - updated_at: 2_000_000, - position_new_path: Some("src/main.rs".to_string()), - position_new_line: Some(42), - position_old_path: None, - position_old_line: None, - resolvable: true, - resolved: false, - resolved_by: None, - noteable_type: Some("Issue".to_string()), - parent_iid: Some(7), - parent_title: Some("Test issue".to_string()), - project_path: "group/project".to_string(), - }], - total_count: 1, - }; - - // Verify csv_escape handles the comma in body correctly - let body = result.notes[0].body.as_deref().unwrap(); - let escaped = csv_escape(body); - assert_eq!(escaped, "\"Hello, world\""); - - // Verify the formatting helpers - assert_eq!( - format_note_type(result.notes[0].note_type.as_deref()), - "Diff" - ); - assert_eq!( - format_note_parent( - result.notes[0].noteable_type.as_deref(), - result.notes[0].parent_iid, - ), - "Issue #7" - ); -} - #[test] fn test_jsonl_output_one_per_line() { let result = NoteListResult {