From b2a03ab0807d8d24f1bfb4ea198672a004bcb29d Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Sat, 20 Aug 2022 11:47:28 +0200 Subject: [PATCH] Make recipe yield for grocery list a parameter --- src/commands/groceries.rs | 5 ++--- src/main.rs | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/groceries.rs b/src/commands/groceries.rs index 9dec036..e93e177 100644 --- a/src/commands/groceries.rs +++ b/src/commands/groceries.rs @@ -19,6 +19,7 @@ pub async fn with( location: &str, start_date: Option, days: u32, + required_yield: f64, ) -> Result<()> { use chrono::{NaiveDateTime, NaiveTime, TimeZone}; let start = start_date @@ -34,9 +35,7 @@ pub async fn with( }; let ids = map_events_to_recipe_ids(api_client, calendar_name, &date_range).await?; - - // TODO: make required_yield configurable! - let ingredients = get_ingredients(api_client, ids, 4.0).await?; + let ingredients = get_ingredients(api_client, ids, required_yield).await?; let ingredients = merge_ingredients(ingredients); let md = prepare_grocery_list(&date_range, &ingredients)?; log::debug!("Saving the following grocery list:\n\n{}", &md); diff --git a/src/main.rs b/src/main.rs index d13d84a..71f5e3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,10 @@ fn setup_args() -> ArgMatches { .value_parser(clap::builder::RangedU64ValueParser::::new().range(1..)) .required(false) .default_value("7")) + .arg(arg!(-y --yield "How many servings per meal to consider") + .value_parser(clap::builder::RangedU64ValueParser::::new().range(1..)) + .required(false) + .default_value("4")) ) .subcommand( Command::new("schedule") @@ -110,6 +114,7 @@ async fn parse_args(args: &ArgMatches) -> Result<()> { .map(|s| chrono::NaiveDate::parse_from_str(&s, "%Y-%m-%d")) .transpose()?; let days = sub_matches.get_one::("days").unwrap(); + let meal_yield = sub_matches.get_one::("yield").unwrap(); let filename = sub_matches.get_one::("filename").unwrap(); commands::groceries::with( &api_client, @@ -117,6 +122,7 @@ async fn parse_args(args: &ArgMatches) -> Result<()> { filename, start_date, *days, + *meal_yield as f64, ) .await }