#[allow(dead_code)] extern crate args; extern crate getopts; use args::{Args, ArgsError}; // use args::validations::{Order,OrderValidation}; use getopts::Occur; use tokio::runtime::Runtime; mod api; #[allow(unused)] struct Opts { registry: String, image: String, exclude: Vec, } fn main() { let mut rt = Runtime::new().unwrap(); let input_args = std::env::args().collect::>(); let _parsed = parse(&input_args).unwrap(); rt.block_on(async { let registry = api::registry::Registry { url: _parsed.registry.as_str(), }; let res = registry.get_repositories().await.unwrap(); if res.repositories.len() == 0 { return; } println!("response :::: {:?}", res); let mut proc_images: Vec = Vec::new(); if _parsed.image.len() > 0 { proc_images.push(_parsed.image); } else { proc_images = res.repositories.to_owned(); } println!("proc images ::: {:?}", proc_images); for img in proc_images.into_iter() { let _repo_tags = registry.get_repository_tags(img.as_str()).await.unwrap(); println!("{:?}", _repo_tags); } }); } fn parse(input: &Vec) -> Result { let mut arg = Args::new("Registry Cleaner", "clean registry images"); arg.flag("h", "help", "print usage"); arg.option( "i", "image", "image name empty is all", "IMAGE", Occur::Optional, Some(String::from("")), ); arg.option( "e", "exclude", "exclude tag no delete", "EXCLUDE", Occur::Optional, None, ); arg.option( "r", "registry", "registry url", "REGISTRY", Occur::Optional, None, ); arg.parse(input).unwrap(); let help: bool = arg.value_of("help").unwrap(); if help { let str = arg.full_usage(); eprintln!("{}", str); std::process::exit(1); } let exclude: Vec = match arg.values_of("exclude") { Ok(strs) => strs, Err(_) => vec![], }; let image: String = match arg.value_of("image") { Ok(v) => v, Err(_) => String::from(""), }; let url: String = arg.value_of("registry").unwrap(); let opts = Opts { image: image.clone(), exclude: exclude.clone(), registry: url, }; Ok(opts) }