use crate::common::report::report_error;
use yash_env::Env;
use yash_env::semantics::Field;
use yash_env::signal::RawNumber;
use yash_env::system::{Fcntl, Isatty, SendSignal, Signals, Write};
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Command {
Send {
signal: RawNumber,
signal_origin: Option<Field>,
targets: Vec<Field>,
},
Print {
signals: Vec<Field>,
verbose: bool,
},
}
pub mod print;
pub mod send;
pub mod syntax;
impl Command {
pub async fn execute<S>(&self, env: &mut Env<S>) -> crate::Result
where
S: Fcntl + Isatty + SendSignal + Signals + Write,
{
match self {
Self::Send {
signal,
signal_origin,
targets,
} => send::execute(env, *signal, signal_origin.as_ref(), targets).await,
Self::Print { signals, verbose } => print::execute(env, signals, *verbose).await,
}
}
}
pub async fn main<S>(env: &mut Env<S>, args: Vec<Field>) -> crate::Result
where
S: Fcntl + Isatty + SendSignal + Signals + Write,
{
match syntax::parse(env, args) {
Ok(command) => command.execute(env).await,
Err(error) => report_error(env, &error).await,
}
}