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,
start_date: Option<NaiveDate>,
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);

View File

@ -55,6 +55,10 @@ fn setup_args() -> ArgMatches {
.value_parser(clap::builder::RangedU64ValueParser::<u32>::new().range(1..))
.required(false)
.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(
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::<u32>("days").unwrap();
let meal_yield = sub_matches.get_one::<u64>("yield").unwrap();
let filename = sub_matches.get_one::<String>("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
}