2021-07-13 16:04:12 +02:00
|
|
|
//! Contains functionality of kill container command
|
2021-10-05 17:38:52 +02:00
|
|
|
use std::{convert::TryInto, path::PathBuf};
|
2021-06-26 10:01:42 +02:00
|
|
|
|
2021-10-05 17:38:52 +02:00
|
|
|
use anyhow::Result;
|
2021-06-26 10:01:42 +02:00
|
|
|
use clap::Clap;
|
|
|
|
|
2021-10-05 17:38:52 +02:00
|
|
|
use crate::{commands::load_container, signal::Signal};
|
2021-06-26 10:01:42 +02:00
|
|
|
|
2021-09-26 02:41:47 +02:00
|
|
|
/// Send the specified signal to the container
|
2021-06-26 10:01:42 +02:00
|
|
|
#[derive(Clap, Debug)]
|
|
|
|
pub struct Kill {
|
2021-10-20 22:10:06 +02:00
|
|
|
#[clap(required = true)]
|
2021-06-26 10:01:42 +02:00
|
|
|
container_id: String,
|
|
|
|
signal: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Kill {
|
|
|
|
pub fn exec(&self, root_path: PathBuf) -> Result<()> {
|
2021-09-21 23:03:12 +02:00
|
|
|
let mut container = load_container(root_path, &self.container_id)?;
|
2021-10-05 17:38:52 +02:00
|
|
|
let signal: Signal = self.signal.as_str().try_into()?;
|
2021-09-20 22:26:35 +02:00
|
|
|
container.kill(signal)
|
2021-06-26 10:01:42 +02:00
|
|
|
}
|
|
|
|
}
|