From e010cb9e9ec4a23ef46ac302e0b1a5c198b5859f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 7 Mar 2021 20:09:11 +0100 Subject: Implement container stop subcommand Signed-off-by: Matthias Beyer --- src/commands/endpoint.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs index 14a4927..240770e 100644 --- a/src/commands/endpoint.rs +++ b/src/commands/endpoint.rs @@ -192,6 +192,7 @@ async fn container(endpoint_names: Vec, Some(("kill", matches)) => container_kill(matches, relevant_endpoint, container_id).await, Some(("delete", _)) => container_delete(relevant_endpoint, container_id).await, Some(("start", _)) => container_start(relevant_endpoint, container_id).await, + Some(("stop", matches)) => container_stop(matches, relevant_endpoint, container_id).await, Some((other, _)) => Err(anyhow!("Unknown subcommand: {}", other)), None => Err(anyhow!("No subcommand")), } @@ -269,6 +270,24 @@ async fn container_start( .map_err(Error::from) } +async fn container_stop( + matches: &ArgMatches, + endpoint: &Endpoint, + container_id: &str, +) -> Result<()> { + let timeout = matches.value_of("timeout").map(u64::from_str).transpose()?.map(std::time::Duration::from_secs); + let prompt = format!("Really stop {}?", container_id); + dialoguer::Confirm::new().with_prompt(prompt).interact()?; + + endpoint + .get_container_by_id(container_id) + .await? + .ok_or_else(|| anyhow!("Cannot find container {} on {}", container_id, endpoint.name()))? + .stop(timeout) + .await + .map_err(Error::from) +} + async fn containers(endpoint_names: Vec, matches: &ArgMatches, -- cgit v1.2.3