Skip to content

Commit

Permalink
Record participants
Browse files Browse the repository at this point in the history
  • Loading branch information
corka149 committed Mar 13, 2022
1 parent 0ab1e90 commit 5d07fe2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
34 changes: 33 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod report;
mod util;

use clap::App;
use std::io;

fn main() {
let _matches = App::new("Protocoler")
Expand All @@ -19,12 +20,43 @@ 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
.into_iter()
.flatten()
.collect::<Vec<record::ProtocolEntry>>();

report::output(entries);
report::output(participants, entries);
}

fn record_participants() -> Vec<String> {
loop {
let participants: Result<Vec<String>, 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::<Vec<String>>()
});

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()
)
}
}
}
17 changes: 12 additions & 5 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtocolEntry>) {
pub fn output(participants: Vec<String>, protocol_entries: Vec<ProtocolEntry>) {
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);
Expand All @@ -37,13 +37,15 @@ fn select_format() -> String {
}
}

fn print_raw(protocol_entries: Vec<ProtocolEntry>) {
fn print_raw(participants: Vec<String>, protocol_entries: Vec<ProtocolEntry>) {
println!("Participants: {:?}", participants);

for e in protocol_entries {
println!("{}", e);
}
}

fn print_markdown(protocol_entries: Vec<ProtocolEntry>) {
fn print_markdown(participants: Vec<String>, protocol_entries: Vec<ProtocolEntry>) {
let mut infos: Vec<ProtocolEntry> = Vec::new();
let mut decisions: Vec<ProtocolEntry> = Vec::new();
let mut tasks: Vec<ProtocolEntry> = Vec::new();
Expand All @@ -58,6 +60,11 @@ fn print_markdown(protocol_entries: Vec<ProtocolEntry>) {

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!("| --- | --- | ---|");
Expand Down

0 comments on commit 5d07fe2

Please sign in to comment.