use crate::app::session_control::Action;
const WATCH: &str = "watch";
const UNWATCH: &str = "unwatch";
pub(crate) fn served_actions() -> impl Iterator<Item = Action> {
Action::ALL.into_iter().filter(|&action| served(action))
}
fn served(action: Action) -> bool {
match action {
Action::List
| Action::Read
| Action::New
| Action::Prompt
| Action::Steer
| Action::Cancel
| Action::Wait => true,
Action::Answer => false,
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ServedTool {
Core(Action),
Watch,
Unwatch,
}
impl ServedTool {
pub(crate) fn from_name(name: &str) -> Option<Self> {
match name {
WATCH => Some(Self::Watch),
UNWATCH => Some(Self::Unwatch),
_ => Self::core(name),
}
}
pub(crate) fn core(name: &str) -> Option<Self> {
Action::from_name(name)
.filter(|&action| served(action))
.map(Self::Core)
}
pub(crate) fn name(self) -> &'static str {
match self {
Self::Core(action) => action.name(),
Self::Watch => WATCH,
Self::Unwatch => UNWATCH,
}
}
}