diff options
author | stuebinm | 2022-02-01 20:02:21 +0100 |
---|---|---|
committer | stuebinm | 2022-02-01 20:37:01 +0100 |
commit | be7cc4ca0b7a168a9c6cd110a74d04c35956cdde (patch) | |
tree | 2fb0d287f335aefe425f68ac3946c8ae600c8592 /src/travelynx.rs | |
parent | 6af74791f87f812516d0158f9124a70d4943e194 (diff) |
pretty print pretty printing code
Diffstat (limited to '')
-rw-r--r-- | src/travelynx.rs | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/src/travelynx.rs b/src/travelynx.rs index a6c59e1..c5351eb 100644 --- a/src/travelynx.rs +++ b/src/travelynx.rs @@ -1,72 +1,74 @@ use clap::Args; -use serde::{Serialize, Deserialize}; use colored::*; +use serde::{Deserialize, Serialize}; use crate::types::Status; #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct Travel { - token: String, - #[serde(flatten)] - action: Action, + token: String, + #[serde(flatten)] + action: Action } #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] #[serde(tag = "action")] pub enum Action { - #[serde(rename = "checkin")] - #[serde(rename_all = "camelCase")] - CheckIn { - token: String, - train: TrainRef, - from_station: String, - #[serde(skip_serializing_if = "Option::is_none")] - to_station: Option<String>, - #[serde(skip_serializing_if = "Option::is_none")] - comment: Option<String>, - }, - #[serde(rename = "checkout")] - #[serde(rename_all = "camelCase")] - CheckOut { - to_station: String, - force: bool, - #[serde(skip_serializing_if = "Option::is_none")] - comment: Option<String>, - token: String - }, - Undo {token: String}, + #[serde(rename = "checkin")] + #[serde(rename_all = "camelCase")] + CheckIn { + token: String, + train: TrainRef, + from_station: String, + #[serde(skip_serializing_if = "Option::is_none")] + to_station: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + comment: Option<String> + }, + #[serde(rename = "checkout")] + #[serde(rename_all = "camelCase")] + CheckOut { + to_station: String, + force: bool, + #[serde(skip_serializing_if = "Option::is_none")] + comment: Option<String>, + token: String + }, + Undo { + token: String + } } #[derive(Args, Serialize, Debug)] pub struct TrainRef { - #[clap(name = "TRAIN TYPE")] - #[serde(rename = "type")] - pub _type: String, - #[clap(name = "NUMBER")] - pub no: String, + #[clap(name = "TRAIN TYPE")] + #[serde(rename = "type")] + pub _type: String, + #[clap(name = "NUMBER")] + pub no: String } impl std::fmt::Display for TrainRef { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{} {}", self._type, self.no) - } + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {}", self._type, self.no) + } } #[derive(Deserialize, Debug)] pub struct Response { - success: Option<bool>, - deprecated: bool, - status: Status, - error: Option<String> + success: Option<bool>, + deprecated: bool, + status: Status, + error: Option<String> } impl std::fmt::Display for Response { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.error { - Some(msg) => write!(f, "{}", msg.red()), - None => write!(f, "{}\n\n{}", "Success!".green(), self.status) - } + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match &self.error { + Some(msg) => write!(f, "{}", msg.red()), + None => write!(f, "{}\n\n{}", "Success!".green(), self.status) } + } } |