pub(super) const NAMESPACES: &[(&str, Namespace)] = &[
("lernie", Namespace::Lernie),
("bl", Namespace::Bl),
("bz", Namespace::Bz),
("bl-delivery", Namespace::BlDelivery),
("bl-tracker", Namespace::BlTracker),
("gesture", Namespace::Gesture),
(crate::wire::SEAT_SUBCMD, Namespace::Seat),
(crate::wire::HOST_SUBCMD, Namespace::ToolHost),
];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum Namespace {
Lernie,
Bl,
Bz,
BlDelivery,
BlTracker,
Gesture,
Seat,
ToolHost,
}
impl Namespace {
pub(super) fn from_arg(arg: &str) -> Option<Self> {
NAMESPACES
.iter()
.find(|(word, _)| *word == arg)
.map(|(_, namespace)| *namespace)
}
pub(super) fn owns_argv(self) -> bool {
match self {
Namespace::Lernie
| Namespace::Bl
| Namespace::Bz
| Namespace::BlDelivery
| Namespace::BlTracker
| Namespace::Gesture
| Namespace::Seat => true,
Namespace::ToolHost => false,
}
}
pub(super) fn run(self, args: &[String]) -> i32 {
match self {
Namespace::Lernie => super::lernie::run(args),
Namespace::Bl => super::bl::run(args),
Namespace::Bz => super::bz::run(args),
Namespace::BlDelivery => super::bl_delivery::run(args),
Namespace::BlTracker => super::bl_tracker::run(args),
Namespace::Gesture => super::gesture::run(args),
Namespace::Seat => super::wire::seat(args),
Namespace::ToolHost => super::wire::tool_host(args),
}
}
}