summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-08 12:13:07 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-03-08 12:45:26 +0100
commit3d363bd203aec1b6ad5c637228cd62811a8a1127 (patch)
treeea4fa19823aefde1afddbd3839833f28baf13d33
parentfaafd9df072c9aaf0e276f4736f3f56011033dc7 (diff)
Refactor filter building into helper function
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/commands/endpoint.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs
index 7542d68..93a969e 100644
--- a/src/commands/endpoint.rs
+++ b/src/commands/endpoint.rs
@@ -173,14 +173,8 @@ async fn containers_list(endpoint_names: Vec<String>,
) -> 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 older_than_filter = get_date_filter("older_than", matches)?;
+ let newer_than_filter = get_date_filter("newer_than", matches)?;
let csv = matches.is_present("csv");
let hdr = crate::commands::util::mk_header([
"Endpoint",
@@ -229,14 +223,8 @@ async fn containers_prune(endpoint_names: Vec<String>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
- 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 older_than_filter = get_date_filter("older_than", matches)?;
+ let newer_than_filter = get_date_filter("newer_than", matches)?;
let stats = connect_to_endpoints(config, &endpoint_names)
.await?
@@ -275,6 +263,15 @@ async fn containers_prune(endpoint_names: Vec<String>,
.await
}
+fn get_date_filter(name: &str, matches: &ArgMatches) -> Result<Option<chrono::DateTime::<chrono::Local>>> {
+ matches.value_of(name)
+ .map(humantime::parse_rfc3339_weak)
+ .transpose()?
+ .map(chrono::DateTime::<chrono::Local>::from)
+ .map(Ok)
+ .transpose()
+}
+
/// Helper function to connect to all endpoints from the configuration, that appear (by name) in
/// the `endpoint_names` list
pub(super) async fn connect_to_endpoints(config: &Configuration, endpoint_names: &[String]) -> Result<Vec<Arc<Endpoint>>> {