Compare commits

..

No commits in common. "05a9669fec107a3668c79e67ab88c8a43672e7f0" and "4bda6e47beff172a6b5f64b37382225491541975" have entirely different histories.

5 changed files with 30 additions and 194 deletions

148
Cargo.lock generated
View File

@ -11,26 +11,6 @@ dependencies = [
"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]]
name = "autocfg"
version = "1.0.1"
@ -92,21 +72,6 @@ dependencies = [
"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]]
name = "core-foundation"
version = "0.9.1"
@ -248,15 +213,6 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "hermit-abi"
version = "0.1.19"
@ -571,30 +527,6 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "proc-macro2"
version = "1.0.28"
@ -604,6 +536,20 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "query-docker-tags"
version = "0.1.0"
dependencies = [
"chrono",
"lazy_static",
"regex",
"reqwest",
"serde",
"serde_json",
"termion",
"tui",
]
[[package]]
name = "quote"
version = "1.0.9"
@ -671,21 +617,6 @@ dependencies = [
"redox_syscall",
]
[[package]]
name = "reel-moby"
version = "0.9.0"
dependencies = [
"chrono",
"lazy_static",
"regex",
"reqwest",
"serde",
"serde_json",
"structopt",
"termion",
"tui",
]
[[package]]
name = "regex"
version = "1.5.4"
@ -845,36 +776,6 @@ dependencies = [
"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]]
name = "syn"
version = "1.0.74"
@ -912,15 +813,6 @@ dependencies = [
"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]]
name = "time"
version = "0.1.44"
@ -1083,18 +975,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "want"
version = "0.3.0"

View File

@ -15,7 +15,6 @@ tui = "0.16"
termion = "1.5"
regex = "1.5.4"
lazy_static = "1.4.0"
structopt = "0.3.23"
[profile.release]
lto = "yes"

View File

@ -1,30 +1,8 @@
use std::path::PathBuf;
use structopt::StructOpt;
mod repo;
mod tags;
mod ui;
mod widget;
/// helps you searching or updating tags of your used docker images
#[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);
ui::Ui::run("enter a repository or select one from docker-compose.yml");
}

View File

@ -12,13 +12,12 @@ use crate::widget::info;
use crate::widget::repo_entry;
use crate::widget::service_switcher;
use crate::widget::tag_list;
use crate::Opt;
pub struct Ui {
pub struct Ui<'a> {
state: State,
repo: crate::widget::repo_entry::RepoEntry,
tags: crate::widget::tag_list::TagList,
services: crate::widget::service_switcher::ServiceSwitcher,
services: crate::widget::service_switcher::ServiceSwitcher<'a>,
info: crate::widget::info::Info,
}
@ -42,28 +41,16 @@ impl std::iter::Iterator for State {
}
}
impl Ui {
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),
};
impl Ui<'_> {
pub fn run(repo_id: &str) {
let mut ui = Ui {
state: State::SelectService,
repo: repo_entry::RepoEntry::new(repo_id),
tags: tag_list::TagList::with_status("Tags are empty"),
services: service_switcher::ServiceSwitcher::new(&opt.config),
services: service_switcher::ServiceSwitcher::new(),
info: info::Info::new("Select image of edit Repository"),
};
if load_repo {
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
}
//setup tui
let stdout = io::stdout().into_raw_mode().unwrap();
let backend = TermionBackend::new(stdout);

View File

@ -3,7 +3,6 @@ use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Write;
use std::path::PathBuf;
use tui::style::{Color, Style};
use tui::widgets::{Block, Borders, List, ListState};
@ -26,26 +25,19 @@ impl fmt::Display for Error {
}
}
pub struct ServiceSwitcher {
pub struct ServiceSwitcher<'a> {
list: Vec<String>,
state: ListState,
changed: bool,
opened_file: PathBuf,
opened_file: &'a str,
}
impl ServiceSwitcher {
pub fn new(file: &Option<PathBuf>) -> Self {
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()),
}
impl ServiceSwitcher<'_> {
pub fn new() -> Self {
let file_list = vec!["docker-compose.yml", "docker-compose.yaml"];
for file in file_list {
let list = match File::open(&file) {
let list = match File::open(file) {
Err(_) => continue,
Ok(file) => {
let buf = BufReader::new(file);
@ -68,7 +60,7 @@ impl ServiceSwitcher {
list: vec![format!("No docker-compose file found")],
state: ListState::default(),
changed: false,
opened_file: PathBuf::new(),
opened_file: "No file",
}
}
@ -80,8 +72,8 @@ impl ServiceSwitcher {
};
let title = match &self.changed {
true => format!("File: *{}*", &self.opened_file.display()),
false => format!("File: {}", &self.opened_file.display()),
true => format!("File: *{}*", self.opened_file),
false => format!("File: {}", self.opened_file),
};
let items: Vec<tui::widgets::ListItem> = self
@ -193,7 +185,7 @@ impl ServiceSwitcher {
/// save the currently opened file
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 {
file.write_all(line.as_bytes())?;
file.write_all("\n".as_bytes())?;