use crate::boundary::{Action, Gesture, Query};
impl Gesture {
pub fn workspace(&self) -> Option<String> {
match self {
Gesture::Act(action) => action.workspace(),
Gesture::Ask(query) => query.workspace(),
}
}
}
impl Action {
pub fn workspace(&self) -> Option<String> {
let mut named = self.clone();
named.workspace_slot().map(std::mem::take)
}
fn workspace_slot(&mut self) -> Option<&mut String> {
match self {
Action::Message { workspace, .. }
| Action::Stop { workspace, .. }
| Action::Interrupt { workspace, .. }
| Action::Scan { workspace }
| Action::Nudge { workspace, .. }
| Action::Retarget { workspace, .. }
| Action::Fork { workspace, .. }
| Action::Prepare { workspace, .. }
| Action::DeleteWorkspace { workspace, .. }
| Action::DeleteAgent { workspace, .. }
| Action::MarkSeen { workspace, .. }
| Action::SetMarks { workspace, .. }
| Action::PickModel { workspace, .. }
| Action::AnswerHold { workspace, .. }
| Action::Floor { workspace, .. }
| Action::Login { workspace, .. } => Some(workspace),
Action::Tune(tuning) => Some(tuning.workspace_slot()),
Action::Prompt { prepared, .. }
| Action::Fan(crate::fan::Verb::Spread { prepared, .. }) => {
Some(&mut prepared.workspace)
}
Action::Enroll(request) => Some(&mut request.workspace),
Action::Monitor(verb) => Some(verb.workspace_slot()),
Action::Fleet(verb) => Some(verb.workspace_slot()),
Action::ApplyConfig { file, .. } => file.workspace_slot(),
Action::Advertise { .. }
| Action::Route(_)
| Action::Ball(_)
| Action::Fan(crate::fan::Verb::Retire { .. } | crate::fan::Verb::Deliver { .. })
| Action::Ack
| Action::ClearTrail => None,
}
}
}
impl Query {
pub fn workspace(&self) -> Option<String> {
let mut named = self.clone();
named.workspace_slot().map(std::mem::take)
}
fn workspace_slot(&mut self) -> Option<&mut String> {
match self {
Query::Conversations { workspace }
| Query::WorkDiff { workspace, .. }
| Query::Science { workspace }
| Query::Transcript { workspace, .. }
| Query::Follow { workspace, .. }
| Query::Steps { workspace, .. }
| Query::Step { workspace, .. }
| Query::Files { workspace, .. }
| Query::Governing { workspace, .. }
| Query::Rail { workspace, .. }
| Query::Inbox { workspace, .. }
| Query::Agent { workspace, .. }
| Query::WorkspaceBalls { workspace }
| Query::Clients { workspace }
| Query::LoginTail { workspace, .. } => Some(workspace),
Query::Config(read) => read.workspace_slot(),
Query::Workspaces
| Query::Balls
| Query::Board
| Query::Attention
| Query::Ops { .. }
| Query::Search { .. }
| Query::Help { .. }
| Query::Invocations
| Query::Capture { .. } => None,
}
}
}
#[cfg(test)]
mod tests;