diff --git a/src/main.rs b/src/main.rs index 9d4648a..95c060f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod report; mod util; use clap::App; +use std::io; fn main() { let _matches = App::new("Protocoler") @@ -19,6 +20,8 @@ clap & Rust. It can output the protocol in different formats. ) .get_matches(); + let participants = record_participants(); + let entries = record::start(util::input); let entries = entries @@ -26,5 +29,34 @@ clap & Rust. It can output the protocol in different formats. .flatten() .collect::>(); - report::output(entries); + report::output(participants, entries); +} + +fn record_participants() -> Vec { + loop { + let participants: Result, io::Error> = + util::input("Participants of meeting? (Separate by comma)").map(|all_participants| { + all_participants + .split(",") + .map(|p| p.trim().to_string()) + .filter(|p| !p.is_empty()) + .collect::>() + }); + + if participants.is_ok() { + let participants = participants.unwrap(); + + println!("{}", participants.len()); + if !participants.is_empty() { + return participants; + } else { + eprintln!("No participants provided!") + } + } else { + eprintln!( + "Error while reading participants: {}", + participants.unwrap_err() + ) + } + } } diff --git a/src/report.rs b/src/report.rs index 84229c1..51a4cf3 100644 --- a/src/report.rs +++ b/src/report.rs @@ -10,10 +10,10 @@ const CSV_FORMAT: &str = "csv"; const ALLOWED_FORMATS: [&str; 3] = [RAW_FORMAT, MARKDOWN_FORMAT, CSV_FORMAT]; /// Outputs the protocol entries in different formats. -pub fn output(protocol_entries: Vec) { +pub fn output(participants: Vec, protocol_entries: Vec) { match select_format().as_str() { - RAW_FORMAT => print_raw(protocol_entries), - MARKDOWN_FORMAT => print_markdown(protocol_entries), + RAW_FORMAT => print_raw(participants, protocol_entries), + MARKDOWN_FORMAT => print_markdown(participants, protocol_entries), CSV_FORMAT => print_csv(protocol_entries), unknown => { eprintln!("Unknown format'{}'", unknown); @@ -37,13 +37,15 @@ fn select_format() -> String { } } -fn print_raw(protocol_entries: Vec) { +fn print_raw(participants: Vec, protocol_entries: Vec) { + println!("Participants: {:?}", participants); + for e in protocol_entries { println!("{}", e); } } -fn print_markdown(protocol_entries: Vec) { +fn print_markdown(participants: Vec, protocol_entries: Vec) { let mut infos: Vec = Vec::new(); let mut decisions: Vec = Vec::new(); let mut tasks: Vec = Vec::new(); @@ -58,6 +60,11 @@ fn print_markdown(protocol_entries: Vec) { println!("# Protocol {}", Local::now().format("%Y-%m-%d")); + println!("\n## Participants\n"); + participants + .iter() + .for_each(|participant| println!("* {}", participant)); + println!("\n## Information\n"); println!("|Time|Said by|text|"); println!("| --- | --- | ---|");