Files
zesdex/src/app/runtime/commands.rs
T

78 lines
2.6 KiB
Rust
Raw Normal View History

//! Maps parsed `/` slash commands into one or more `Action` variants
//! that `apply_action` can process.
use crate::app::runtime::actions::Action;
use crate::app::state::types::Overlay;
use crate::controller::command::Command;
/// Convert a parsed `Command` into the corresponding sequence of `Action`s.
///
/// Flow: match each `Command` variant to its handler — most produce a
/// single `Action` (open an overlay, dispatch an OAuth flow, open the
/// editor, etc.); some produce an `Action::SystemNote` for errors or
/// informational responses.
///
/// Return: a `Vec<Action>` (always non-empty) to be applied sequentially
/// by `apply_action`.
pub fn apply_command(command: Command) -> Vec<Action> {
match command {
Command::Help => {
vec![Action::OpenOverlay(Overlay::Help)]
}
Command::Quit => {
vec![Action::QuitConfirm]
}
Command::McpOpen => {
vec![Action::OpenOverlay(Overlay::Mcp)]
}
Command::ClearConfirm => {
vec![Action::OpenOverlay(Overlay::ClearConfirm)]
}
Command::Clear => {
vec![Action::SystemNote {
kind: "clear".to_string(),
message: "transcript cleared".to_string(),
}]
}
Command::Login { provider } if provider.is_empty() => {
vec![Action::SystemNote {
kind: "error".to_string(),
message: "Usage: /login <provider>".to_string(),
}]
}
Command::Login { provider } => {
vec![Action::StartOAuth { provider }]
}
Command::Edit(path) if path == "." || path.is_empty() => {
vec![Action::SystemNote {
kind: "info".to_string(),
message: "Usage: /edit <path>\nOpens a file for inline editing.\nExample: /edit src/main.rs".to_string(),
}]
}
Command::Edit(path) => {
vec![Action::OpenEditor { path }]
}
Command::McpAdd { name, command } => {
vec![Action::McpAdd { name, command }]
}
Command::ModelList => {
vec![Action::ModelList]
}
Command::Compact => {
vec![Action::Compact]
}
Command::TodoOpen => {
vec![Action::OpenOverlay(Overlay::Todo)]
}
Command::UsageOpen => {
vec![Action::OpenOverlay(Overlay::Usage)]
}
Command::Unknown(cmd) => {
vec![Action::SystemNote {
kind: "error".to_string(),
message: format!("unknown command: {cmd}"),
}]
}
}
}