1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
use crate::errors::*; use colored::*; use chrono::NaiveDateTime; use strum_macros::{EnumString, AsRefStr, Display}; use serde::{Serialize, Deserialize}; use std::ops::Deref; use std::str::FromStr; pub mod api; pub mod auth; pub mod config; pub mod errors; pub mod utils; #[derive(Debug, Clone, Copy, PartialEq, Display, EnumString, AsRefStr, Serialize, Deserialize)] #[strum(serialize_all = "kebab-case")] #[serde(rename_all = "kebab-case")] pub enum Distro { Debian, Archlinux, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct PkgRelease { pub name: String, pub version: String, pub status: Status, pub distro: String, pub suite: String, pub architecture: String, pub url: String, pub built_at: Option<NaiveDateTime>, pub attestation: Option<String>, pub next_retry: Option<NaiveDateTime>, } impl PkgRelease { pub fn new(name: String, version: String, distro: Distro, suite: String, architecture: String, url: String) -> PkgRelease { PkgRelease { name, version, status: Status::Unknown, distro: distro.to_string(), suite, architecture, url, built_at: None, attestation: None, next_retry: None, } } } #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum Status { #[serde(rename = "GOOD")] Good, #[serde(rename = "BAD")] Bad, #[serde(rename = "UNKWN")] Unknown, } impl Status { pub fn fancy(&self) -> String { match self { Status::Good => "GOOD ".green().to_string(), Status::Bad => "BAD ".red().to_string(), Status::Unknown => "UNKWN".yellow().to_string(), } } } impl Deref for Status { type Target = str; fn deref(&self) -> &'static str { match self { Status::Good => "GOOD", Status::Bad => "BAD", Status::Unknown => "UNKWN", } } } impl FromStr for Status { type Err = Error; fn from_str(s: &str) -> Result<Status> { match s { "GOOD" => Ok(Status::Good), "BAD" => Ok(Status::Bad), "UNKWN" => Ok(Status::Unknown), _ => bail!("Unknown status: {:?}", s), } } } #[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } }