Add vegetarian switch
This commit is contained in:
@@ -23,6 +23,10 @@ pub struct Args {
|
||||
/// Offset of days in the future (valid inputs 0-7)
|
||||
#[arg(short, long, default_value_t = 0)]
|
||||
pub days: u8,
|
||||
|
||||
/// Show the vegetarian menu
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
pub vegetarian: bool,
|
||||
}
|
||||
|
||||
pub fn get_args() -> Args {
|
||||
|
14
src/main.rs
14
src/main.rs
@@ -12,18 +12,6 @@ mod cli;
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args = cli::get_args();
|
||||
exec_arguments(&args).await?;
|
||||
//let shedhalle = mensa::Mensa::from(mensa::MensaName::Shedhalle);
|
||||
//let morgenstelle = mensa::Mensa::from(mensa::MensaName::Morgenstelle);
|
||||
//if let mensa::Mensa::Shedhalle(resp) = shedhalle.await? {
|
||||
// let data = resp.today().iter().map(|&x| x.get_short_info()).collect::<Vec<(&str, String, &str)>>();
|
||||
// table_short(data);
|
||||
//}
|
||||
|
||||
//if let mensa::Mensa::Morgenstelle(resp) = morgenstelle.await? {
|
||||
// let data = resp.today().iter().map(|&x| x.get_short_info()).collect::<Vec<(&str, String, &str)>>();
|
||||
// table_short(data);
|
||||
//}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -46,7 +34,7 @@ async fn exec_arguments(args: &cli::Args) -> Result<(), Box<dyn std::error::Erro
|
||||
}
|
||||
|
||||
fn exec_arg_helper(args: &cli::Args, m: &dyn mensa::Mealplan) {
|
||||
if let Some(menus) = m.nth(args.days) {
|
||||
if let Some(menus) = m.nth(args.days, args.vegetarian) {
|
||||
if args.plaintext {
|
||||
for i in menus.iter() {
|
||||
i.print_short_info();
|
||||
|
18
src/mensa.rs
18
src/mensa.rs
@@ -13,7 +13,7 @@ pub trait Mealplan {
|
||||
fn id(&self) -> &str;
|
||||
fn name(&self) -> &str;
|
||||
fn today(&self) -> Vec<&Menu>;
|
||||
fn nth(&self, days: u8) -> Option<Vec<&Menu>>;
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<Vec<&Menu>>;
|
||||
}
|
||||
|
||||
pub enum Mensa {
|
||||
@@ -88,11 +88,15 @@ impl Mealplan for MensaShedhalle {
|
||||
self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect()
|
||||
}
|
||||
|
||||
fn nth(&self, days: u8) -> Option<Vec<&Menu>> {
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<Vec<&Menu>> {
|
||||
match get_nth_date(days) {
|
||||
Some(dt) => {
|
||||
let local = format!("{}", dt.format("%Y-%m-%d"));
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect())
|
||||
if vegetarian {
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local && x.menu_line.contains("veg")).collect())
|
||||
} else {
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect())
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
@@ -122,11 +126,15 @@ impl Mealplan for MensaMorgenstelle {
|
||||
self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect()
|
||||
}
|
||||
|
||||
fn nth(&self, days: u8) -> Option<Vec<&Menu>> {
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<Vec<&Menu>> {
|
||||
match get_nth_date(days) {
|
||||
Some(dt) => {
|
||||
let local = format!("{}", dt.format("%Y-%m-%d"));
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect())
|
||||
if vegetarian {
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local && x.menu_line.contains("veg")).collect())
|
||||
} else {
|
||||
Some(self.canteen.menus.iter().filter(|&x| x.menu_date == local).collect())
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
|
Reference in New Issue
Block a user