61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
use journal::{journal::JSONJournal, types::Consumer};
|
|
|
|
use crate::{
|
|
args::JournalLocation, display::print_ingestion_log, formatting::format_session_title,
|
|
};
|
|
|
|
#[derive(Debug, Clone, clap::Args)]
|
|
#[group(requires = "journal_location")]
|
|
pub struct PrintSessionArgs {
|
|
pub session_title: String,
|
|
|
|
#[command(flatten)]
|
|
pub journal_location: JournalLocation,
|
|
|
|
#[arg(long)]
|
|
pub substance_filter: Option<Vec<String>>,
|
|
#[arg(long, value_delimiter = ',')]
|
|
pub consumer_filter: Option<Vec<String>>,
|
|
}
|
|
|
|
pub fn parse_consumer_filter(consumer_filter: Option<Vec<String>>) -> Option<Vec<Consumer>> {
|
|
match consumer_filter {
|
|
Some(consumer_filter) => {
|
|
let mut consumers: Vec<Consumer> = Vec::new();
|
|
for consumer in consumer_filter.into_iter() {
|
|
let mut consumer = consumer;
|
|
if consumer.is_empty() {
|
|
consumer = "default".to_string();
|
|
}
|
|
|
|
consumers.push(Consumer::from(consumer.as_str()));
|
|
}
|
|
Some(consumers)
|
|
}
|
|
None => None,
|
|
}
|
|
}
|
|
|
|
pub fn print_session(args: &PrintSessionArgs) -> Result<(), Box<dyn std::error::Error>> {
|
|
let journal = JSONJournal::load(&args.journal_location.journal_file)?;
|
|
let session = journal
|
|
.first_session_by_title(&args.session_title)
|
|
.expect("could not find session");
|
|
|
|
//println!("{:#?}", &session);
|
|
|
|
println!("{}", format_session_title(&session));
|
|
|
|
let substance_filter = args.substance_filter.clone();
|
|
let consumer_filter = parse_consumer_filter(args.consumer_filter.clone());
|
|
|
|
print_ingestion_log(
|
|
&journal,
|
|
&session,
|
|
substance_filter.as_ref(),
|
|
consumer_filter.as_ref(),
|
|
);
|
|
|
|
Ok(())
|
|
}
|