diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-04-27 10:01:33 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-05-11 11:13:05 +0200 |
commit | 6829525b6109b10a320860cee61208d5b016e643 (patch) | |
tree | 6170e64fcf745e736002c2e8534442feccf07faf /src/cli.rs | |
parent | 675d69a211d3d1fe3c4d66aec8f8f57fbbf73920 (diff) |
Refactor: Construct common arguments with helper functions
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/cli.rs')
-rw-r--r-- | src/cli.rs | 94 |
1 files changed, 30 insertions, 64 deletions
@@ -972,53 +972,14 @@ pub fn cli<'a>() -> App<'a> { .subcommand(App::new("prune") .version(crate_version!()) .about("Remove exited containers") - .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") - ) + .arg(arg_older_than_date()) + .arg(arg_newer_than_date()) ) .subcommand(App::new("stop") .version(crate_version!()) .about("Stop running containers") - .arg(Arg::new("older_than") - .required(false) - .multiple(false) - .long("older-than") - .takes_value(true) - .value_name("DATE") - .about("Stop 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("Stop only containers that are newer than DATE") - .validator(parse_date_from_string) - .conflicts_with("older_than") - ) - + .arg(arg_older_than_date()) + .arg(arg_newer_than_date()) .arg(Arg::new("timeout") .required(false) .multiple(false) @@ -1058,27 +1019,8 @@ pub fn cli<'a>() -> App<'a> { .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") - ) + .arg(arg_older_than_date()) + .arg(arg_newer_than_date()) ) .subcommand(App::new("top") .version(crate_version!()) @@ -1258,6 +1200,30 @@ fn dir_exists_validator(s: &str) -> Result<(), String> { } } +fn arg_older_than_date<'a>() -> Arg<'a> { + 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") +} + +fn arg_newer_than_date<'a>() -> Arg<'a> { + 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") +} + fn parse_date_from_string(s: &str) -> std::result::Result<(), String> { humantime::parse_rfc3339_weak(s).map_err(|e| e.to_string()).map(|_| ()) } |