Compare commits
7 Commits
6c83683a4a
...
13350f872a
Author | SHA1 | Date | |
---|---|---|---|
|
13350f872a | ||
|
c8915f828f | ||
|
88070489f3 | ||
|
d1ef5c6755 | ||
|
e98c5e7a12 | ||
|
b6dbcd8eba | ||
|
7720ed3102 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -673,7 +673,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reel-moby"
|
||||
version = "1.0.0"
|
||||
version = "1.2.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
[package]
|
||||
name = "reel-moby"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
version = "1.2.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
28
src/common/display_duration_ext.rs
Normal file
28
src/common/display_duration_ext.rs
Normal file
@ -0,0 +1,28 @@
|
||||
pub trait DisplayDurationExt {
|
||||
/// displays a duration in a human readable form
|
||||
fn display(&self) -> String;
|
||||
}
|
||||
|
||||
impl DisplayDurationExt for chrono::Duration {
|
||||
fn display(&self) -> String {
|
||||
if self.num_weeks() == 52 {
|
||||
format!("{} Year", (self.num_weeks() / 52) as i32)
|
||||
} else if self.num_weeks() > 103 {
|
||||
format!("{} Years", (self.num_weeks() / 52) as i32)
|
||||
} else if self.num_days() == 1 {
|
||||
format!("{} Day", self.num_days())
|
||||
} else if self.num_days() > 1 {
|
||||
format!("{} Days", self.num_days())
|
||||
} else if self.num_hours() == 1 {
|
||||
format!("{} Hour", self.num_hours())
|
||||
} else if self.num_hours() > 1 {
|
||||
format!("{} Hours", self.num_hours())
|
||||
} else if self.num_minutes() == 1 {
|
||||
format!("{} Minute", self.num_minutes())
|
||||
} else if self.num_minutes() > 1 {
|
||||
format!("{} Minutes", self.num_minutes())
|
||||
} else {
|
||||
format!("{} Seconds", self.num_seconds())
|
||||
}
|
||||
}
|
||||
}
|
1
src/common/mod.rs
Normal file
1
src/common/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod display_duration_ext;
|
@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod common;
|
||||
mod repo;
|
||||
mod repository;
|
||||
mod ui;
|
||||
@ -9,10 +10,6 @@ mod widget;
|
||||
/// helps you searching or updating tags of your used docker images
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub struct Opt {
|
||||
/// Show architectures of images and their sizes
|
||||
#[structopt(short, long)]
|
||||
verbose: bool,
|
||||
|
||||
/// A custom path to a docker-compose file
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
file: Option<PathBuf>,
|
||||
|
105
src/repo.rs
105
src/repo.rs
@ -30,7 +30,7 @@ pub enum Repo {
|
||||
/// the second &str will the the identifier for the image
|
||||
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
||||
lazy_static::lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap();
|
||||
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\-\./:]+)").unwrap();
|
||||
}
|
||||
let caps = match REGEX.captures(input) {
|
||||
Some(caps) => caps,
|
||||
@ -103,58 +103,79 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_split_repo_without_tag() {
|
||||
use crate::repo::split_repo_without_tag as test_fn;
|
||||
assert_eq!(test_fn(""), Err(Error::MisformedInput));
|
||||
assert_eq!(test_fn("NGINX"), Err(Error::MisformedInput));
|
||||
assert_eq!(test_fn("nginx"), Ok(Repo::Project("nginx".into())));
|
||||
assert_eq!(
|
||||
test_fn("library/nginx"),
|
||||
Ok(Repo::WithOrga("library".into(), "nginx".into()))
|
||||
);
|
||||
assert_eq!(
|
||||
test_fn("ghcr.io/library/nginx"),
|
||||
let input: Vec<(&str, Result<Repo, Error>)> = vec![
|
||||
("", Err(Error::MisformedInput)),
|
||||
("NGINX", Err(Error::MisformedInput)),
|
||||
("nginx", Ok(Repo::Project("nginx".into()))),
|
||||
(
|
||||
"library/nginx",
|
||||
Ok(Repo::WithOrga("library".into(), "nginx".into())),
|
||||
),
|
||||
(
|
||||
"ghcr.io/library/nginx",
|
||||
Ok(Repo::WithServer(
|
||||
"ghcr.io".into(),
|
||||
"library".into(),
|
||||
"nginx".into(),
|
||||
))
|
||||
);
|
||||
)),
|
||||
),
|
||||
(
|
||||
"te-st/test-hypen",
|
||||
Ok(Repo::WithOrga("te-st".into(), "test-hypen".into())),
|
||||
),
|
||||
(
|
||||
"test/test.dot",
|
||||
Ok(Repo::WithOrga("test".into(), "test.dot".into())),
|
||||
),
|
||||
];
|
||||
|
||||
for i in input {
|
||||
assert_eq!(super::split_repo_without_tag(i.0), i.1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_yaml_image() {
|
||||
use crate::repo::match_yaml_image as test_fn;
|
||||
assert_eq!(test_fn(""), Err(Error::NoTagFound));
|
||||
assert_eq!(test_fn("version: '2'"), Err(Error::NoTagFound));
|
||||
assert_eq!(test_fn("image: "), Err(Error::NoTagFound));
|
||||
assert_eq!(test_fn(" image: "), Err(Error::NoTagFound));
|
||||
assert_eq!(test_fn(" image: nginx"), Ok((" image: ", "nginx")));
|
||||
assert_eq!(
|
||||
test_fn(" image: library/nginx"),
|
||||
Ok((" image: ", "library/nginx"))
|
||||
);
|
||||
assert_eq!(
|
||||
test_fn(" image: ghcr.io/library/nginx"),
|
||||
Ok((" image: ", "ghcr.io/library/nginx"))
|
||||
);
|
||||
assert_eq!(test_fn("# image: nginx"), Err(Error::NoTagFound));
|
||||
assert_eq!(
|
||||
test_fn(" image: nginx #comment"),
|
||||
Ok((" image: ", "nginx"))
|
||||
);
|
||||
let input: Vec<(&str, Result<(&str, &str), Error>)> = vec![
|
||||
("", Err(Error::NoTagFound)),
|
||||
("version: '2'", Err(Error::NoTagFound)),
|
||||
("image: ", Err(Error::NoTagFound)),
|
||||
(" image: ", Err(Error::NoTagFound)),
|
||||
(" image: nginx", Ok((" image: ", "nginx"))),
|
||||
(" image: library/nginx", Ok((" image: ", "library/nginx"))),
|
||||
(
|
||||
" image: gchr.io/library/nginx",
|
||||
Ok((" image: ", "gchr.io/library/nginx")),
|
||||
),
|
||||
(" image: nginx # comment", Ok((" image: ", "nginx"))),
|
||||
(" image: test-hyphen", Ok((" image: ", "test-hyphen"))),
|
||||
(" image: test.dot", Ok((" image: ", "test.dot"))),
|
||||
];
|
||||
|
||||
for i in input {
|
||||
assert_eq!(super::match_yaml_image(i.0), i.1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_tag_from_repo() {
|
||||
use crate::repo::split_tag_from_repo as test_fn;
|
||||
assert_eq!(test_fn("nginx"), Ok(("nginx", "")));
|
||||
assert_eq!(test_fn("library/nginx"), Ok(("library/nginx", "")));
|
||||
assert_eq!(
|
||||
test_fn("ghcr.io/library/nginx"),
|
||||
Ok(("ghcr.io/library/nginx", ""))
|
||||
);
|
||||
assert_eq!(test_fn("nginx:"), Ok(("nginx", "")));
|
||||
assert_eq!(test_fn("nginx:1"), Ok(("nginx", "1")));
|
||||
assert_eq!(test_fn("nginx:latest"), Ok(("nginx", "latest")));
|
||||
let input: Vec<(&str, Result<(&str, &str), super::Error>)> = vec![
|
||||
("nginx", Ok(("nginx", ""))),
|
||||
("library/nginx", Ok(("library/nginx", ""))),
|
||||
("ghcr.io/library/nginx", Ok(("ghcr.io/library/nginx", ""))),
|
||||
("nginx:", Ok(("nginx", ""))),
|
||||
("nginx:1", Ok(("nginx", "1"))),
|
||||
("nginx:latest", Ok(("nginx", "latest"))),
|
||||
("hy-phen:latest", Ok(("hy-phen", "latest"))),
|
||||
("test.dot:latest", Ok(("test.dot", "latest"))),
|
||||
(
|
||||
"woodpeckerci/woodpecker-server",
|
||||
Ok(("woodpeckerci/woodpecker-server", "")),
|
||||
),
|
||||
];
|
||||
|
||||
for i in input {
|
||||
assert_eq!(super::split_tag_from_repo(i.0), i.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ use std::fmt;
|
||||
|
||||
use chrono::DateTime;
|
||||
|
||||
use crate::common::display_duration_ext::DisplayDurationExt;
|
||||
use crate::repo;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -54,7 +55,7 @@ impl Tag {
|
||||
let now = chrono::Utc::now();
|
||||
let rfc3339 = DateTime::parse_from_rfc3339(last_updated).unwrap();
|
||||
let dif = now - rfc3339.with_timezone(&chrono::Utc);
|
||||
format!(", {} old", format_time_nice(dif))
|
||||
format!(", {} old", dif.display())
|
||||
}
|
||||
};
|
||||
|
||||
@ -109,29 +110,6 @@ impl Repo {
|
||||
}
|
||||
}
|
||||
|
||||
/// converts a given duration to a readable string
|
||||
fn format_time_nice(time: chrono::Duration) -> String {
|
||||
if time.num_weeks() == 52 {
|
||||
format!("{} Year", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_weeks() > 103 {
|
||||
format!("{} Years", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_days() == 1 {
|
||||
format!("{} Day", time.num_days())
|
||||
} else if time.num_days() > 1 {
|
||||
format!("{} Days", time.num_days())
|
||||
} else if time.num_hours() == 1 {
|
||||
format!("{} Hour", time.num_hours())
|
||||
} else if time.num_hours() > 1 {
|
||||
format!("{} Hours", time.num_hours())
|
||||
} else if time.num_minutes() == 1 {
|
||||
format!("{} Minute", time.num_minutes())
|
||||
} else if time.num_minutes() > 1 {
|
||||
format!("{} Minutes", time.num_minutes())
|
||||
} else {
|
||||
format!("{} Seconds", time.num_seconds())
|
||||
}
|
||||
}
|
||||
|
||||
/// checks the repo name and may add a prefix for official images
|
||||
pub fn check_repo(name: &str) -> Result<String, Error> {
|
||||
let repo = match repo::split_tag_from_repo(name) {
|
||||
|
@ -54,7 +54,7 @@ impl std::iter::Iterator for State {
|
||||
|
||||
impl Ui {
|
||||
pub fn run(opt: &Opt) {
|
||||
let repo_id = opt.repo.as_ref().map(|repo| String::as_str(repo));
|
||||
let repo_id = opt.repo.as_deref();
|
||||
|
||||
let mut ui = Ui {
|
||||
state: State::SelectService,
|
||||
|
@ -49,7 +49,7 @@ pub struct NoYaml {
|
||||
|
||||
impl NoYaml {
|
||||
pub fn run(opt: &Opt) {
|
||||
let repo_id = opt.repo.as_ref().map(|repo| String::as_str(repo));
|
||||
let repo_id = opt.repo.as_deref();
|
||||
|
||||
let mut ui = NoYaml {
|
||||
state: State::EditRepo,
|
||||
|
@ -26,14 +26,14 @@ impl Details {
|
||||
let mut lines = vec![format!("{:^10}|{:^6}|{:^6}", "ARCH", "OS", "SIZE")];
|
||||
for d in &self.details {
|
||||
lines.push(format!(
|
||||
"{:^10}|{:^6}|{:^6}",
|
||||
"{:^10}|{:^6}|{:^6}MB",
|
||||
format!(
|
||||
"{}{}",
|
||||
d.arch.clone().unwrap_or_default(),
|
||||
d.variant.clone().unwrap_or_default()
|
||||
),
|
||||
d.os.clone().unwrap_or_default(),
|
||||
format!("{}MB", d.size.unwrap_or_default() / 1024 / 1024)
|
||||
d.size.unwrap_or_default() / 1024 / 1024,
|
||||
));
|
||||
}
|
||||
lines
|
||||
|
Loading…
Reference in New Issue
Block a user