summaryrefslogtreecommitdiffstats
path: root/src/commands/endpoint.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-07 15:36:26 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-07 15:36:26 +0200
commit3f3ca1259919cb69f8915b11db9b21d9c03aadbc (patch)
treec5ca554d61caed8e29547670b02346bb2d2977c7 /src/commands/endpoint.rs
parentdcc8b42810d34b2b906f0307c26c4826d16ad997 (diff)
parentb665c7cd4aa4ea900dc194a6ba5ad9de527f978c (diff)
Merge branch 'db-release-arg-date-filter'
Diffstat (limited to 'src/commands/endpoint.rs')
-rw-r--r--src/commands/endpoint.rs32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs
index 4de51d2..6fd7d69 100644
--- a/src/commands/endpoint.rs
+++ b/src/commands/endpoint.rs
@@ -182,8 +182,8 @@ async fn containers_list(endpoint_names: Vec<EndpointName>,
) -> Result<()> {
let list_stopped = matches.is_present("list_stopped");
let filter_image = matches.value_of("filter_image");
- let older_than_filter = get_date_filter("older_than", matches)?;
- let newer_than_filter = get_date_filter("newer_than", matches)?;
+ let older_than_filter = crate::commands::util::get_date_filter("older_than", matches)?;
+ let newer_than_filter = crate::commands::util::get_date_filter("newer_than", matches)?;
let csv = matches.is_present("csv");
let hdr = crate::commands::util::mk_header([
"Endpoint",
@@ -232,8 +232,8 @@ async fn containers_prune(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
- let older_than_filter = get_date_filter("older_than", matches)?;
- let newer_than_filter = get_date_filter("newer_than", matches)?;
+ let older_than_filter = crate::commands::util::get_date_filter("older_than", matches)?;
+ let newer_than_filter = crate::commands::util::get_date_filter("newer_than", matches)?;
let stats = connect_to_endpoints(config, &endpoint_names)
.await?
@@ -279,8 +279,8 @@ async fn containers_top(endpoint_names: Vec<EndpointName>,
config: &Configuration,
) -> Result<()> {
let limit = matches.value_of("limit").map(usize::from_str).transpose()?;
- let older_than_filter = get_date_filter("older_than", matches)?;
- let newer_than_filter = get_date_filter("newer_than", matches)?;
+ let older_than_filter = crate::commands::util::get_date_filter("older_than", matches)?;
+ let newer_than_filter = crate::commands::util::get_date_filter("newer_than", matches)?;
let csv = matches.is_present("csv");
let data = connect_to_endpoints(config, &endpoint_names)
@@ -374,8 +374,8 @@ async fn containers_stop(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
- let older_than_filter = get_date_filter("older_than", matches)?;
- let newer_than_filter = get_date_filter("newer_than", matches)?;
+ let older_than_filter = crate::commands::util::get_date_filter("older_than", matches)?;
+ let newer_than_filter = crate::commands::util::get_date_filter("newer_than", matches)?;
let stop_timeout = matches.value_of("timeout")
.map(u64::from_str)
@@ -422,22 +422,6 @@ async fn containers_stop(endpoint_names: Vec<EndpointName>,
}
-fn get_date_filter(name: &str, matches: &ArgMatches) -> Result<Option<chrono::DateTime::<chrono::Local>>> {
- matches.value_of(name)
- .map(humantime::parse_duration)
- .transpose()?
- .map(chrono::Duration::from_std)
- .transpose()?
- .map(|dur| {
- chrono::offset::Local::now()
- .checked_sub_signed(dur)
- .ok_or_else(|| anyhow!("Time calculation would overflow"))
- .with_context(|| anyhow!("Cannot subtract {} from 'now'", dur))
- .map_err(Error::from)
- })
- .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: &[EndpointName]) -> Result<Vec<Arc<Endpoint>>> {