Compare commits
No commits in common. "13350f872a35ef015d323b0d6bdb59e08579a656" and "b6dbcd8ebac2aa0220455883b723d785b4ceb6c4" have entirely different histories.
13350f872a
...
b6dbcd8eba
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -673,7 +673,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reel-moby"
|
||||
version = "1.2.1"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
[package]
|
||||
name = "reel-moby"
|
||||
version = "1.2.1"
|
||||
edition = "2021"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 76 KiB |
@ -1,28 +0,0 @@
|
||||
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 +0,0 @@
|
||||
pub mod display_duration_ext;
|
@ -1,7 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod common;
|
||||
mod repo;
|
||||
mod repository;
|
||||
mod ui;
|
||||
@ -10,6 +9,10 @@ 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>,
|
||||
|
@ -27,8 +27,11 @@ impl Images {
|
||||
.images
|
||||
.iter()
|
||||
.map(|d| super::TagDetails {
|
||||
arch: Some(d.architecture.clone()),
|
||||
variant: Some(d.variant.clone().unwrap_or_default()),
|
||||
arch: Some(format!(
|
||||
"{}{}",
|
||||
d.architecture.clone(),
|
||||
d.variant.clone().unwrap_or_default()
|
||||
)),
|
||||
os: Some(d.os.clone()),
|
||||
size: Some(d.size),
|
||||
})
|
||||
|
@ -33,6 +33,7 @@ impl Ghcr {
|
||||
.header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token))
|
||||
.send()
|
||||
{
|
||||
// let response = match reqwest::blocking::get(url) {
|
||||
Ok(result) => result,
|
||||
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
||||
};
|
||||
|
@ -5,7 +5,6 @@ use std::fmt;
|
||||
|
||||
use chrono::DateTime;
|
||||
|
||||
use crate::common::display_duration_ext::DisplayDurationExt;
|
||||
use crate::repo;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -31,11 +30,25 @@ impl fmt::Display for Error {
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct TagDetails {
|
||||
pub arch: Option<String>,
|
||||
pub variant: Option<String>,
|
||||
pub os: Option<String>,
|
||||
pub size: Option<usize>,
|
||||
}
|
||||
|
||||
impl fmt::Display for TagDetails {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let size = match self.size {
|
||||
None => "".to_string(),
|
||||
Some(s) => (s / 1024 / 1024).to_string(),
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"{}|{}MB",
|
||||
self.arch.as_ref().unwrap_or(&"".to_string()),
|
||||
size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Tag {
|
||||
name: String,
|
||||
@ -49,13 +62,22 @@ impl Tag {
|
||||
}
|
||||
|
||||
pub fn get_name_with_details(&self) -> String {
|
||||
//architecture infos
|
||||
let mut arch = String::new();
|
||||
for image in self.details.iter().take(1) {
|
||||
arch.push_str(&format!("{}", image));
|
||||
}
|
||||
for image in self.details.iter().skip(1) {
|
||||
arch.push_str(&format!(", {}", image));
|
||||
}
|
||||
|
||||
let dif = match &self.last_updated {
|
||||
None => "".to_string(),
|
||||
Some(last_updated) => {
|
||||
let now = chrono::Utc::now();
|
||||
let rfc3339 = DateTime::parse_from_rfc3339(last_updated).unwrap();
|
||||
let dif = now - rfc3339.with_timezone(&chrono::Utc);
|
||||
format!(", {} old", dif.display())
|
||||
format!(" vor {}", format_time_nice(dif))
|
||||
}
|
||||
};
|
||||
|
||||
@ -110,6 +132,29 @@ impl Repo {
|
||||
}
|
||||
}
|
||||
|
||||
/// converts a given duration to a readable string
|
||||
fn format_time_nice(time: chrono::Duration) -> String {
|
||||
if time.num_weeks() == 52 {
|
||||
format!("{} Jahr", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_weeks() > 103 {
|
||||
format!("{} Jahren", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_days() == 1 {
|
||||
format!("{} Tag", time.num_days())
|
||||
} else if time.num_days() > 1 {
|
||||
format!("{} Tagen", time.num_days())
|
||||
} else if time.num_hours() == 1 {
|
||||
format!("{} Stunde", time.num_hours())
|
||||
} else if time.num_hours() > 1 {
|
||||
format!("{} Stunden", time.num_hours())
|
||||
} else if time.num_minutes() == 1 {
|
||||
format!("{} Minute", time.num_minutes())
|
||||
} else if time.num_minutes() > 1 {
|
||||
format!("{} Minuten", time.num_minutes())
|
||||
} else {
|
||||
format!("{} Sekunden", 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,13 @@ impl std::iter::Iterator for State {
|
||||
|
||||
impl Ui {
|
||||
pub fn run(opt: &Opt) {
|
||||
let repo_id = opt.repo.as_deref();
|
||||
let (repo_id, load_repo) = match &opt.repo {
|
||||
None => (
|
||||
"enter a repository here or select one from file widget",
|
||||
false,
|
||||
),
|
||||
Some(repo) => (String::as_str(repo), true),
|
||||
};
|
||||
|
||||
let mut ui = Ui {
|
||||
state: State::SelectService,
|
||||
@ -65,7 +71,7 @@ impl Ui {
|
||||
info: info::Info::new("Select image of edit Repository"),
|
||||
};
|
||||
|
||||
if opt.repo.is_none() {
|
||||
if load_repo {
|
||||
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
|
||||
}
|
||||
|
||||
|
@ -49,18 +49,26 @@ pub struct NoYaml {
|
||||
|
||||
impl NoYaml {
|
||||
pub fn run(opt: &Opt) {
|
||||
let repo_id = opt.repo.as_deref();
|
||||
let (repo, load_repo) = match &opt.repo {
|
||||
None => (
|
||||
repo_entry::RepoEntry::new(
|
||||
"enter a repository or select one from docker-compose.yml",
|
||||
),
|
||||
false,
|
||||
),
|
||||
Some(repo_id) => (repo_entry::RepoEntry::new(repo_id), true),
|
||||
};
|
||||
|
||||
let mut ui = NoYaml {
|
||||
state: State::EditRepo,
|
||||
repo: repo_entry::RepoEntry::new(repo_id),
|
||||
repo,
|
||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||
details: details::Details::new(),
|
||||
info: info::Info::new("could not find a docker-compose file"),
|
||||
};
|
||||
|
||||
// load tags if a repository was given thorugh paramter
|
||||
if opt.repo.is_none() {
|
||||
if load_repo {
|
||||
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,10 @@ impl Details {
|
||||
let mut lines = vec![format!("{:^10}|{:^6}|{:^6}", "ARCH", "OS", "SIZE")];
|
||||
for d in &self.details {
|
||||
lines.push(format!(
|
||||
"{:^10}|{:^6}|{:^6}MB",
|
||||
format!(
|
||||
"{}{}",
|
||||
d.arch.clone().unwrap_or_default(),
|
||||
d.variant.clone().unwrap_or_default()
|
||||
),
|
||||
"{:^10}|{:^6}|{:^6}",
|
||||
d.arch.clone().unwrap_or_default(),
|
||||
d.os.clone().unwrap_or_default(),
|
||||
d.size.unwrap_or_default() / 1024 / 1024,
|
||||
format!("{}MB", d.size.unwrap_or_default() / 1024 / 1024)
|
||||
));
|
||||
}
|
||||
lines
|
||||
|
@ -7,17 +7,14 @@ pub struct RepoEntry {
|
||||
text: String,
|
||||
old_text: String,
|
||||
changed: bool,
|
||||
default_text: bool,
|
||||
}
|
||||
|
||||
impl RepoEntry {
|
||||
pub fn new(text: Option<&str>) -> Self {
|
||||
let default_text = "enter a repository here or select one from file widget";
|
||||
pub fn new(text: &str) -> Self {
|
||||
Self {
|
||||
text: String::from(text.unwrap_or(default_text)),
|
||||
old_text: String::from(text.unwrap_or(default_text)),
|
||||
text: String::from(text),
|
||||
old_text: String::from(text),
|
||||
changed: false,
|
||||
default_text: text.is_none(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,14 +56,9 @@ impl RepoEntry {
|
||||
Key::Char(c) => {
|
||||
self.text.push(c);
|
||||
self.changed = true;
|
||||
self.default_text = false;
|
||||
}
|
||||
Key::Backspace => {
|
||||
if self.default_text {
|
||||
self.text = String::new();
|
||||
} else {
|
||||
self.text.pop();
|
||||
}
|
||||
self.text.pop();
|
||||
self.changed = true;
|
||||
}
|
||||
Key::Esc => {
|
||||
|
Loading…
Reference in New Issue
Block a user