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(),
}
}
pub(crate) fn with_workspace(self, name: &str) -> Self {
match self {
Gesture::Act(action) => Gesture::Act(action.with_workspace(name)),
Gesture::Ask(query) => Gesture::Ask(query.with_workspace(name)),
}
}
}
impl Action {
pub fn workspace(&self) -> Option<String> {
let mut named = self.clone();
named.workspace_slot().map(std::mem::take)
}
pub(crate) fn with_workspace(mut self, name: &str) -> Self {
if let Some(slot) = self.workspace_slot() {
name.clone_into(slot);
}
self
}
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, .. } => Some(workspace),
Action::Prompt { prepared, .. }
| Action::Fan(crate::fan::Verb::Spread { prepared, .. }) => {
Some(&mut prepared.workspace)
}
Action::Monitor(verb) => Some(verb.workspace_slot()),
Action::Fleet(verb) => Some(verb.workspace_slot()),
Action::Advertise { .. }
| Action::Route(_)
| Action::ApplyConfig { .. }
| Action::Close { .. }
| Action::Assign { .. }
| Action::Release { .. }
| Action::Create { .. }
| Action::Update { .. }
| 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)
}
pub(crate) fn with_workspace(mut self, name: &str) -> Self {
if let Some(slot) = self.workspace_slot() {
name.clone_into(slot);
}
self
}
fn workspace_slot(&mut self) -> Option<&mut String> {
match self {
Query::Conversations { workspace }
| Query::WorkDiff { workspace, .. }
| Query::Science { workspace }
| Query::Lineages { workspace }
| Query::Models { workspace, .. }
| Query::Marks { 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::Providers { workspace }
| Query::WorkspaceBalls { workspace }
| Query::Clients { workspace } => Some(workspace),
Query::Workspaces
| Query::Balls
| Query::Board
| Query::Attention
| Query::Ops { .. }
| Query::Search { .. }
| Query::Help { .. }
| Query::ReadConfig { .. }
| Query::Invocations
| Query::Capture { .. } => None,
}
}
}
#[cfg(test)]
mod tests;