summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-07 19:56:19 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-07 21:50:29 +0100
commit0d4c7ae44f5e6bb6885a57742c2c5d447709601d (patch)
tree5af61b293ec909cb56f2fee42c3b965e78036cff
parentdc77417f60659a4919fb04bc9b14a65e3c6d3b03 (diff)
Add container kill subcommand
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/commands/endpoint.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs
index 0bede59..03625cf 100644
--- a/src/commands/endpoint.rs
+++ b/src/commands/endpoint.rs
@@ -11,6 +11,7 @@
use std::str::FromStr;
use std::sync::Arc;
+use anyhow::Error;
use anyhow::Result;
use anyhow::anyhow;
use clap::ArgMatches;
@@ -188,6 +189,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((other, _)) => Err(anyhow!("Unknown subcommand: {}", other)),
None => Err(anyhow!("No subcommand")),
}
@@ -210,6 +212,29 @@ async fn container_top(
crate::commands::util::display_data(hdr, top.processes, csv)
}
+async fn container_kill(
+ matches: &ArgMatches,
+ endpoint: &Endpoint,
+ container_id: &str,
+) -> Result<()> {
+ let signal = matches.value_of("signal");
+ let prompt = if let Some(sig) = signal.as_ref() {
+ format!("Really kill {} with {}?", container_id, sig)
+ } else {
+ format!("Really kill {}?", 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()))?
+ .kill(signal)
+ .await
+ .map_err(Error::from)
+}
+
async fn containers(endpoint_names: Vec<String>,
matches: &ArgMatches,
config: &Configuration,