Make recipe yield for grocery list a parameter

This commit is contained in:
Matteo Settenvini 2022-08-20 11:47:28 +02:00
parent 1d5faae1f6
commit b2a03ab080
Signed by: matteo
GPG Key ID: 8576CC1AD97D42DF
2 changed files with 8 additions and 3 deletions

View File

@ -19,6 +19,7 @@ pub async fn with(
location: &str, location: &str,
start_date: Option<NaiveDate>, start_date: Option<NaiveDate>,
days: u32, days: u32,
required_yield: f64,
) -> Result<()> { ) -> Result<()> {
use chrono::{NaiveDateTime, NaiveTime, TimeZone}; use chrono::{NaiveDateTime, NaiveTime, TimeZone};
let start = start_date 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?; let ids = map_events_to_recipe_ids(api_client, calendar_name, &date_range).await?;
let ingredients = get_ingredients(api_client, ids, required_yield).await?;
// TODO: make required_yield configurable!
let ingredients = get_ingredients(api_client, ids, 4.0).await?;
let ingredients = merge_ingredients(ingredients); let ingredients = merge_ingredients(ingredients);
let md = prepare_grocery_list(&date_range, &ingredients)?; let md = prepare_grocery_list(&date_range, &ingredients)?;
log::debug!("Saving the following grocery list:\n\n{}", &md); log::debug!("Saving the following grocery list:\n\n{}", &md);

View File

@ -55,6 +55,10 @@ fn setup_args() -> ArgMatches {
.value_parser(clap::builder::RangedU64ValueParser::<u32>::new().range(1..)) .value_parser(clap::builder::RangedU64ValueParser::<u32>::new().range(1..))
.required(false) .required(false)
.default_value("7")) .default_value("7"))
.arg(arg!(-y --yield <n> "How many servings per meal to consider")
.value_parser(clap::builder::RangedU64ValueParser::<u64>::new().range(1..))
.required(false)
.default_value("4"))
) )
.subcommand( .subcommand(
Command::new("schedule") 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")) .map(|s| chrono::NaiveDate::parse_from_str(&s, "%Y-%m-%d"))
.transpose()?; .transpose()?;
let days = sub_matches.get_one::<u32>("days").unwrap(); let days = sub_matches.get_one::<u32>("days").unwrap();
let meal_yield = sub_matches.get_one::<u64>("yield").unwrap();
let filename = sub_matches.get_one::<String>("filename").unwrap(); let filename = sub_matches.get_one::<String>("filename").unwrap();
commands::groceries::with( commands::groceries::with(
&api_client, &api_client,
@ -117,6 +122,7 @@ async fn parse_args(args: &ArgMatches) -> Result<()> {
filename, filename,
start_date, start_date,
*days, *days,
*meal_yield as f64,
) )
.await .await
} }