Compare commits

..

No commits in common. "74006af796461dc5b4ee7636074582ac01207a16" and "45f2bb64b04c6f98556487610d9cf53c8cc6c735" have entirely different histories.

4 changed files with 42 additions and 35 deletions

View File

@ -2,16 +2,24 @@ use std::fmt;
use regex::Regex;
// use crate::common;
#[derive(Debug, PartialEq)]
pub enum Error {
// Conversion,
// Empty,
NoTagFound,
// InvalidChar,
MisformedInput,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
// Error::Conversion => write!(f, "Conversion error"),
// Error::Empty => write!(f, "Input is empty"),
Error::NoTagFound => write!(f, "Expected a tag"),
// Error::InvalidChar => write!(f, "Invalid character found"),
Error::MisformedInput => write!(f, "Unexpected input"),
}
}

View File

@ -7,6 +7,7 @@ use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
struct ImageDetails {
architecture: String,
// os: String,
size: usize,
}
@ -24,30 +25,6 @@ pub struct Images {
last_updated: String,
}
impl fmt::Display for Images {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//architecture infos
let mut arch = String::new();
for image in self.images.iter().take(1) {
arch.push_str(&format!("{}", image));
}
for image in self.images.iter().skip(1) {
arch.push_str(&format!(", {}", image));
}
let now = chrono::Utc::now();
let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap();
let dif = now - rfc3339.with_timezone(&chrono::Utc);
write!(
f,
"{} vor {} [{}]",
self.tag_name,
format_time_nice(dif),
arch
)
}
}
#[derive(Deserialize)]
pub struct Tags {
count: usize,
@ -64,6 +41,7 @@ pub enum Error {
Converting(String),
/// invalid repos show a valid json with 0 tags
NoTagsFound,
NoNextPage,
}
impl fmt::Display for Error {
@ -71,6 +49,7 @@ impl fmt::Display for Error {
match self {
Error::Fetching(s) => write!(f, "Fetching error: {}", s),
Error::Converting(s) => write!(f, "Converting error: {}", s),
Error::NoNextPage => write!(f, "No next page available"),
Error::NoTagsFound => write!(f, "Given Repo has 0 tags. Is it valid?"),
}
}
@ -119,17 +98,38 @@ impl Tags {
}
/// returns tags of next page
pub fn next_page(&self) -> Option<Self> {
pub fn next_page(&self) -> Result<Self, Error> {
match &self.next_page {
Some(url) => match Self::with_url(url) {
Ok(tags) => Some(tags),
Err(_) => None,
},
None => None,
Some(url) => Self::with_url(url),
None => Err(Error::NoNextPage),
}
}
}
impl fmt::Display for Images {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//architecture infos
let mut arch = String::new();
for image in self.images.iter().take(1) {
arch.push_str(&format!("{}", image));
}
for image in self.images.iter().skip(1) {
arch.push_str(&format!(", {}", image));
}
let now = chrono::Utc::now();
let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap();
let dif = now - rfc3339.with_timezone(&chrono::Utc);
write!(
f,
"{} vor {} [{}]",
self.tag_name,
format_time_nice(dif),
arch
)
}
}
/// converts a given duration to a readable string
fn format_time_nice(time: chrono::Duration) -> String {
if time.num_weeks() == 52 {

View File

@ -122,7 +122,6 @@ impl Ui {
State::SelectTag => {
let mut repo = ui.repo.get();
let tag = match ui.tags.get_selected() {
Err(tag_list::Error::NextPageSelected) => continue,
Err(e) => {
ui.info.set_info(&format!("{}", e));
continue;

View File

@ -68,8 +68,8 @@ impl TagList {
.collect();
match tags.next_page() {
None => (),
Some(new_tags) => {
Err(_) => (),
Ok(new_tags) => {
lines.push(Line::NextPage(String::from("load more tags")));
tags = new_tags;
}
@ -149,8 +149,8 @@ impl TagList {
fn load_next_page(&mut self) {
match &self.tags {
Some(tags) => match tags.next_page() {
None => (),
Some(new_tags) => {
Err(_) => (),
Ok(new_tags) => {
//load new tags object
self.tags = Some(new_tags);