Compare commits
4 Commits
4bda6e47be
...
05a9669fec
Author | SHA1 | Date | |
---|---|---|---|
|
05a9669fec | ||
|
8f03f7c14b | ||
|
14658e9253 | ||
|
c8b2bf991c |
148
Cargo.lock
generated
148
Cargo.lock
generated
@ -11,6 +11,26 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -72,6 +92,21 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "2.33.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
|
"atty",
|
||||||
|
"bitflags",
|
||||||
|
"strsim",
|
||||||
|
"textwrap",
|
||||||
|
"unicode-width",
|
||||||
|
"vec_map",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@ -213,6 +248,15 @@ version = "0.11.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-segmentation",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.19"
|
||||||
@ -527,6 +571,30 @@ version = "0.2.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.28"
|
version = "1.0.28"
|
||||||
@ -536,20 +604,6 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "query-docker-tags"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"chrono",
|
|
||||||
"lazy_static",
|
|
||||||
"regex",
|
|
||||||
"reqwest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"termion",
|
|
||||||
"tui",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
@ -617,6 +671,21 @@ dependencies = [
|
|||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reel-moby"
|
||||||
|
version = "0.9.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"lazy_static",
|
||||||
|
"regex",
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"structopt",
|
||||||
|
"termion",
|
||||||
|
"tui",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.5.4"
|
version = "1.5.4"
|
||||||
@ -776,6 +845,36 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt"
|
||||||
|
version = "0.3.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"lazy_static",
|
||||||
|
"structopt-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt-derive"
|
||||||
|
version = "0.4.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.74"
|
version = "1.0.74"
|
||||||
@ -813,6 +912,15 @@ dependencies = [
|
|||||||
"redox_termios",
|
"redox_termios",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
@ -975,6 +1083,18 @@ version = "0.2.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vec_map"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -15,6 +15,7 @@ tui = "0.16"
|
|||||||
termion = "1.5"
|
termion = "1.5"
|
||||||
regex = "1.5.4"
|
regex = "1.5.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
structopt = "0.3.23"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "yes"
|
lto = "yes"
|
||||||
|
26
src/main.rs
26
src/main.rs
@ -1,8 +1,30 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod repo;
|
mod repo;
|
||||||
mod tags;
|
mod tags;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
fn main() {
|
/// helps you searching or updating tags of your used docker images
|
||||||
ui::Ui::run("enter a repository or select one from docker-compose.yml");
|
#[derive(StructOpt, Debug)]
|
||||||
|
#[structopt(name = "main")]
|
||||||
|
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))]
|
||||||
|
config: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Give a Repository identifier, e.g. library/nginx
|
||||||
|
#[structopt(short, long, parse(from_str))]
|
||||||
|
repo: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
//parse parameter
|
||||||
|
let opt = Opt::from_args();
|
||||||
|
ui::Ui::run(&opt);
|
||||||
}
|
}
|
||||||
|
23
src/ui.rs
23
src/ui.rs
@ -12,12 +12,13 @@ use crate::widget::info;
|
|||||||
use crate::widget::repo_entry;
|
use crate::widget::repo_entry;
|
||||||
use crate::widget::service_switcher;
|
use crate::widget::service_switcher;
|
||||||
use crate::widget::tag_list;
|
use crate::widget::tag_list;
|
||||||
|
use crate::Opt;
|
||||||
|
|
||||||
pub struct Ui<'a> {
|
pub struct Ui {
|
||||||
state: State,
|
state: State,
|
||||||
repo: crate::widget::repo_entry::RepoEntry,
|
repo: crate::widget::repo_entry::RepoEntry,
|
||||||
tags: crate::widget::tag_list::TagList,
|
tags: crate::widget::tag_list::TagList,
|
||||||
services: crate::widget::service_switcher::ServiceSwitcher<'a>,
|
services: crate::widget::service_switcher::ServiceSwitcher,
|
||||||
info: crate::widget::info::Info,
|
info: crate::widget::info::Info,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,16 +42,28 @@ impl std::iter::Iterator for State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ui<'_> {
|
impl Ui {
|
||||||
pub fn run(repo_id: &str) {
|
pub fn run(opt: &Opt) {
|
||||||
|
let (repo_id, load_repo) = match &opt.repo {
|
||||||
|
None => (
|
||||||
|
"enter a repository or select one from docker-compose.yml",
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
Some(repo) => (String::as_str(repo), true),
|
||||||
|
};
|
||||||
|
|
||||||
let mut ui = Ui {
|
let mut ui = Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
repo: repo_entry::RepoEntry::new(repo_id),
|
repo: repo_entry::RepoEntry::new(repo_id),
|
||||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||||
services: service_switcher::ServiceSwitcher::new(),
|
services: service_switcher::ServiceSwitcher::new(&opt.config),
|
||||||
info: info::Info::new("Select image of edit Repository"),
|
info: info::Info::new("Select image of edit Repository"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if load_repo {
|
||||||
|
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
|
||||||
|
}
|
||||||
|
|
||||||
//setup tui
|
//setup tui
|
||||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
let stdout = io::stdout().into_raw_mode().unwrap();
|
||||||
let backend = TermionBackend::new(stdout);
|
let backend = TermionBackend::new(stdout);
|
||||||
|
@ -3,6 +3,7 @@ use std::fs::File;
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use tui::style::{Color, Style};
|
use tui::style::{Color, Style};
|
||||||
use tui::widgets::{Block, Borders, List, ListState};
|
use tui::widgets::{Block, Borders, List, ListState};
|
||||||
@ -25,19 +26,26 @@ impl fmt::Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServiceSwitcher<'a> {
|
pub struct ServiceSwitcher {
|
||||||
list: Vec<String>,
|
list: Vec<String>,
|
||||||
state: ListState,
|
state: ListState,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
opened_file: &'a str,
|
opened_file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServiceSwitcher<'_> {
|
impl ServiceSwitcher {
|
||||||
pub fn new() -> Self {
|
pub fn new(file: &Option<PathBuf>) -> Self {
|
||||||
let file_list = vec!["docker-compose.yml", "docker-compose.yaml"];
|
let mut file_list = vec![
|
||||||
|
PathBuf::from("docker-compose.yml"),
|
||||||
|
PathBuf::from("docker-compose.yaml"),
|
||||||
|
];
|
||||||
|
match &file {
|
||||||
|
None => (),
|
||||||
|
Some(file) => file_list.insert(0, file.clone()),
|
||||||
|
}
|
||||||
|
|
||||||
for file in file_list {
|
for file in file_list {
|
||||||
let list = match File::open(file) {
|
let list = match File::open(&file) {
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let buf = BufReader::new(file);
|
let buf = BufReader::new(file);
|
||||||
@ -60,7 +68,7 @@ impl ServiceSwitcher<'_> {
|
|||||||
list: vec![format!("No docker-compose file found")],
|
list: vec![format!("No docker-compose file found")],
|
||||||
state: ListState::default(),
|
state: ListState::default(),
|
||||||
changed: false,
|
changed: false,
|
||||||
opened_file: "No file",
|
opened_file: PathBuf::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +80,8 @@ impl ServiceSwitcher<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let title = match &self.changed {
|
let title = match &self.changed {
|
||||||
true => format!("File: *{}*", self.opened_file),
|
true => format!("File: *{}*", &self.opened_file.display()),
|
||||||
false => format!("File: {}", self.opened_file),
|
false => format!("File: {}", &self.opened_file.display()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let items: Vec<tui::widgets::ListItem> = self
|
let items: Vec<tui::widgets::ListItem> = self
|
||||||
@ -185,7 +193,7 @@ impl ServiceSwitcher<'_> {
|
|||||||
|
|
||||||
/// save the currently opened file
|
/// save the currently opened file
|
||||||
pub fn save(&mut self) -> Result<(), std::io::Error> {
|
pub fn save(&mut self) -> Result<(), std::io::Error> {
|
||||||
let mut file = File::create(self.opened_file)?;
|
let mut file = File::create(&self.opened_file)?;
|
||||||
for line in &self.list {
|
for line in &self.list {
|
||||||
file.write_all(line.as_bytes())?;
|
file.write_all(line.as_bytes())?;
|
||||||
file.write_all("\n".as_bytes())?;
|
file.write_all("\n".as_bytes())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user