passes through a String variable before being sent to stdout

This commit is contained in:
Mylloon 2022-01-03 18:40:20 +01:00
parent ddf20746e2
commit a2a62b0fec
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -24,44 +24,45 @@ pub async fn connexion(
trait Affichage { trait Affichage {
/// Affichage propre de l'équipe /// Affichage propre de l'équipe
fn print(self); fn fprint(self) -> String;
} }
impl Affichage for mattermost_api::models::TeamInformation { impl Affichage for mattermost_api::models::TeamInformation {
fn print(self) { fn fprint(self) -> String {
println!("ID => {}", self.id); let mut res: String = String::from("");
res += &format!("ID => {}", self.id);
println!("Type => {}", self.type_); res += &format!("\nType => {}", self.type_);
println!("Nom => {}", self.name); res += &format!("\nNom => {}", self.name);
println!("Nom d'affichage => {}", self.display_name); res += &format!("\nNom d'affichage => {}", self.display_name);
if !self.description.is_empty() { if !self.description.is_empty() {
println!("Description => {}", self.description); res += &format!("\nDescription => {}", self.description);
} }
// La date fournis par Mattermost est incohérente ? ex: 15/08/53977 le 03/01/2022 // La date fournis par Mattermost est incohérente ? ex: 15/08/53977 le 03/01/2022
let format_date = "le %d/%m/%Y à %T"; let format_date = "le %d/%m/%Y à %T (UTC)";
let creation: DateTime<Utc> = let creation: DateTime<Utc> =
DateTime::from_utc(NaiveDateTime::from_timestamp(self.create_at, 0), Utc); DateTime::from_utc(NaiveDateTime::from_timestamp(self.create_at, 0), Utc);
println!("Date de création => {}", creation.format(format_date)); res += &format!("\nDate de création => {}", creation.format(format_date));
let mise_a_jour: DateTime<Utc> = let mise_a_jour: DateTime<Utc> =
DateTime::from_utc(NaiveDateTime::from_timestamp(self.update_at, 0), Utc); DateTime::from_utc(NaiveDateTime::from_timestamp(self.update_at, 0), Utc);
println!( res += &format!(
"Dernière mise-à-jour => {}", "\nDernière mise-à-jour => {}",
mise_a_jour.format(format_date) mise_a_jour.format(format_date)
); );
if self.delete_at != 0 { if self.delete_at != 0 {
let suppression: DateTime<Utc> = let suppression: DateTime<Utc> =
DateTime::from_utc(NaiveDateTime::from_timestamp(self.delete_at, 0), Utc); DateTime::from_utc(NaiveDateTime::from_timestamp(self.delete_at, 0), Utc);
println!("Date de suppression => {}", suppression.format(format_date)); res += &format!("\nDate de suppression => {}", suppression.format(format_date));
} }
println!("Email => {}", self.email); res += &format!("\nEmail => {}", self.email);
let invitation; let invitation;
if self.allow_open_invite { if self.allow_open_invite {
@ -69,17 +70,19 @@ impl Affichage for mattermost_api::models::TeamInformation {
} else { } else {
invitation = "Faux"; invitation = "Faux";
} }
println!("Invitation ouverte à tous => {}", invitation); res += &format!("\nInvitation ouverte à tous => {}", invitation);
if !self.allowed_domains.is_empty() { if !self.allowed_domains.is_empty() {
println!("Nom de domaines autorisés => {}", self.allowed_domains); res += &format!("\nNom de domaines autorisés => {}", self.allowed_domains);
} }
println!("ID d'invitation => {}", self.invite_id); res += &format!("\nID d'invitation => {}", self.invite_id);
if let Some(id) = self.policy_id { if let Some(id) = self.policy_id {
println!("ID de la politique d'utilisation => {}", id); res += &format!("\nID de la politique d'utilisation => {}", id);
} }
res
} }
} }
@ -89,7 +92,7 @@ pub async fn test(api: &mattermost_api::client::Mattermost, equipe: &str) {
match team_info { match team_info {
Ok(infos) => { Ok(infos) => {
infos.print(); println!("{}", infos.fprint());
} }
Err(e) => { Err(e) => {
println!("Error: {}", e); println!("Error: {}", e);