diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-03-07 20:03:20 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-03-07 21:50:29 +0100 |
commit | 0819cd678b40051e1ac6022dfdc57e1690544628 (patch) | |
tree | 62dead41d193a72038c21e975a0f75d427e0e804 | |
parent | 0d4c7ae44f5e6bb6885a57742c2c5d447709601d (diff) |
Implement container delete subcommand
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/commands/endpoint.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs index 03625cf..ec5b2ef 100644 --- a/src/commands/endpoint.rs +++ b/src/commands/endpoint.rs @@ -190,6 +190,7 @@ async fn container(endpoint_names: Vec<String>, match matches.subcommand() { Some(("top", matches)) => container_top(matches, relevant_endpoint, container_id).await, Some(("kill", matches)) => container_kill(matches, relevant_endpoint, container_id).await, + Some(("delete", _)) => container_delete(relevant_endpoint, container_id).await, Some((other, _)) => Err(anyhow!("Unknown subcommand: {}", other)), None => Err(anyhow!("No subcommand")), } @@ -235,6 +236,23 @@ async fn container_kill( .map_err(Error::from) } +async fn container_delete( + endpoint: &Endpoint, + container_id: &str, +) -> Result<()> { + let prompt = format!("Really delete {}?", 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()))? + .delete() + .await + .map_err(Error::from) +} + + async fn containers(endpoint_names: Vec<String>, matches: &ArgMatches, config: &Configuration, |