summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/commands/endpoint.rs19
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,