Compare commits

..

4 Commits

Author SHA1 Message Date
Thomas Eppers
05a9669fec Merge branch 'dev/parameter' 2021-10-20 13:35:06 +02:00
Thomas Eppers
8f03f7c14b updated Cargo.lock 2021-10-20 13:21:14 +02:00
Thomas Eppers
14658e9253 implemented custom docker-compose file 2021-10-17 03:23:26 +02:00
Thomas Eppers
c8b2bf991c added parameter handling for binary 2021-10-17 02:37:28 +02:00
5 changed files with 195 additions and 31 deletions

148
Cargo.lock generated
View File

@ -11,6 +11,26 @@ 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"
@ -72,6 +92,21 @@ 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"
@ -213,6 +248,15 @@ 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"
@ -527,6 +571,30 @@ 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"
@ -536,20 +604,6 @@ 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"
@ -617,6 +671,21 @@ 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"
@ -776,6 +845,36 @@ 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"
@ -813,6 +912,15 @@ 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"
@ -975,6 +1083,18 @@ 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,6 +15,7 @@ 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,8 +1,30 @@
use std::path::PathBuf;
use structopt::StructOpt;
mod repo;
mod tags;
mod ui;
mod widget;
fn main() {
ui::Ui::run("enter a repository or select one from docker-compose.yml");
/// 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);
}

View File

@ -12,12 +12,13 @@ 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<'a> {
pub struct Ui {
state: State,
repo: crate::widget::repo_entry::RepoEntry,
tags: crate::widget::tag_list::TagList,
services: crate::widget::service_switcher::ServiceSwitcher<'a>,
services: crate::widget::service_switcher::ServiceSwitcher,
info: crate::widget::info::Info,
}
@ -41,16 +42,28 @@ impl std::iter::Iterator for State {
}
}
impl Ui<'_> {
pub fn run(repo_id: &str) {
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),
};
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(),
services: service_switcher::ServiceSwitcher::new(&opt.config),
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,6 +3,7 @@ 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};
@ -25,19 +26,26 @@ impl fmt::Display for Error {
}
}
pub struct ServiceSwitcher<'a> {
pub struct ServiceSwitcher {
list: Vec<String>,
state: ListState,
changed: bool,
opened_file: &'a str,
opened_file: PathBuf,
}
impl ServiceSwitcher<'_> {
pub fn new() -> Self {
let file_list = vec!["docker-compose.yml", "docker-compose.yaml"];
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()),
}
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);
@ -60,7 +68,7 @@ impl ServiceSwitcher<'_> {
list: vec![format!("No docker-compose file found")],
state: ListState::default(),
changed: false,
opened_file: "No file",
opened_file: PathBuf::new(),
}
}
@ -72,8 +80,8 @@ impl ServiceSwitcher<'_> {
};
let title = match &self.changed {
true => format!("File: *{}*", self.opened_file),
false => format!("File: {}", self.opened_file),
true => format!("File: *{}*", &self.opened_file.display()),
false => format!("File: {}", &self.opened_file.display()),
};
let items: Vec<tui::widgets::ListItem> = self
@ -185,7 +193,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())?;