mirror of
https://github.com/MalteT/mensa.git
synced 2024-10-22 21:59:17 +02:00
parent
ab9bd9801c
commit
9158875169
|
@ -1,6 +1,6 @@
|
|||
use chrono::Duration;
|
||||
use reqwest::blocking::Client;
|
||||
use serde::{de::DeserializeOwned, Deserialize};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use tracing::info;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
@ -9,18 +9,18 @@ use crate::{
|
|||
cache,
|
||||
config::CanteensState,
|
||||
error::{Error, Result},
|
||||
geoip, get_sane_terminal_dimensions, ENDPOINT, TTL_CANTEENS,
|
||||
geoip, get_sane_terminal_dimensions, print_json, ENDPOINT, TTL_CANTEENS,
|
||||
};
|
||||
|
||||
const ADRESS_INDENT: &str = " ";
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Canteen {
|
||||
id: usize,
|
||||
name: String,
|
||||
//city: String,
|
||||
city: String,
|
||||
address: String,
|
||||
//oordinates: [f32; 2],
|
||||
coordinates: [f32; 2],
|
||||
}
|
||||
|
||||
impl Canteen {
|
||||
|
@ -58,10 +58,15 @@ impl Canteen {
|
|||
PaginatedList::from(&state.client, url, *TTL_CANTEENS)?.try_flatten_and_collect()
|
||||
}
|
||||
|
||||
pub fn print_all(state: &CanteensState, canteens: &[Self]) {
|
||||
for canteen in canteens {
|
||||
println!();
|
||||
canteen.print(state);
|
||||
pub fn print_all(state: &CanteensState, canteens: &[Self]) -> Result<()> {
|
||||
if state.args.json {
|
||||
print_json(&canteens)
|
||||
} else {
|
||||
for canteen in canteens {
|
||||
println!();
|
||||
canteen.print(state);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ pub struct Args {
|
|||
)]
|
||||
pub color: ColorWhen,
|
||||
|
||||
/// Print plain json. Useful for shell scripts.
|
||||
/// Output json. Useful for shell scripts.
|
||||
#[structopt(long, global = true, takes_value = false)]
|
||||
pub json: bool,
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ fn real_main() -> Result<()> {
|
|||
Some(Command::Canteens(cmd)) => {
|
||||
let state = State::from(state, cmd);
|
||||
let canteens = Canteen::fetch(&state)?;
|
||||
Canteen::print_all(&state, &canteens);
|
||||
Canteen::print_all(&state, &canteens)?;
|
||||
}
|
||||
Some(Command::Tags) => {
|
||||
Tag::print_all(&state)?;
|
||||
|
|
Loading…
Reference in a new issue