diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-03-07 20:09:11 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-03-07 21:50:29 +0100 |
commit | e010cb9e9ec4a23ef46ac302e0b1a5c198b5859f (patch) | |
tree | 557f5884f620c8887b400a54245dcaa05bb65380 /src | |
parent | b1cbb697325f4acc9a6d4c77f16702f6f319f244 (diff) |
Implement container stop subcommand
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/endpoint.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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<String>, 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<String>, matches: &ArgMatches, |