diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/cli.rs | 43 | ||||
-rw-r--r-- | src/commands/endpoint.rs | 14 |
3 files changed, 58 insertions, 0 deletions
@@ -31,6 +31,7 @@ futures = "0.3" getset = "0.1" git2 = "0.13" handlebars = { version = "3", features = ["no_logging"] } +humantime = "2.1" indicatif = "0.15" indoc = "1" itertools = "0.10" @@ -889,6 +889,45 @@ pub fn cli<'a>() -> App<'a> { .takes_value(false) .about("Format output as CSV") ) + + .arg(Arg::new("list_stopped") + .required(false) + .multiple(false) + .long("list-stopped") + .takes_value(false) + .about("List stopped containers too") + ) + + .arg(Arg::new("filter_image") + .required(false) + .multiple(false) + .long("image") + .takes_value(true) + .value_name("IMAGE") + .about("List only containers of IMAGE") + ) + + .arg(Arg::new("older_than") + .required(false) + .multiple(false) + .long("older-than") + .takes_value(true) + .value_name("DATE") + .about("List only containers that are older than DATE") + .validator(parse_date_from_string) + .conflicts_with("newer_than") + ) + + .arg(Arg::new("newer_than") + .required(false) + .multiple(false) + .long("newer-than") + .takes_value(true) + .value_name("DATE") + .about("List only containers that are newer than DATE") + .validator(parse_date_from_string) + .conflicts_with("older_than") + ) ) ) ) @@ -969,6 +1008,10 @@ fn dir_exists_validator(s: &str) -> Result<(), String> { } } +fn parse_date_from_string(s: &str) -> std::result::Result<(), String> { + humantime::parse_rfc3339_weak(s).map_err(|e| e.to_string()).map(|_| ()) +} + #[cfg(test)] mod tests { use super::env_pass_validator; diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs index 4882364..abb09bb 100644 --- a/src/commands/endpoint.rs +++ b/src/commands/endpoint.rs @@ -167,6 +167,16 @@ async fn containers_list(endpoint_names: Vec<String>, matches: &ArgMatches, config: &Configuration, ) -> Result<()> { + let list_stopped = matches.is_present("list_stopped"); + let filter_image = matches.value_of("filter_image"); + let older_than_filter = matches.value_of("older_than") + .map(humantime::parse_rfc3339_weak) + .transpose()? + .map(chrono::DateTime::<chrono::Local>::from); + let newer_than_filter = matches.value_of("newer_than") + .map(humantime::parse_rfc3339_weak) + .transpose()? + .map(chrono::DateTime::<chrono::Local>::from); let csv = matches.is_present("csv"); let hdr = crate::commands::util::mk_header([ "Endpoint", @@ -190,6 +200,10 @@ async fn containers_list(endpoint_names: Vec<String>, let endpoint_name = tpl.0; tpl.1 .into_iter() + .filter(|stat| list_stopped || stat.state != "exited") + .filter(|stat| filter_image.map(|fim| fim == stat.image).unwrap_or(true)) + .filter(|stat| older_than_filter.as_ref().map(|time| time > &stat.created).unwrap_or(true)) + .filter(|stat| newer_than_filter.as_ref().map(|time| time < &stat.created).unwrap_or(true)) .map(|stat| { vec![ endpoint_name.clone(), |