| 1 | //! `/router` command (#6525): set up the per-turn router for Auto model |
| 2 | //! routing. `/model router …` is the same command. Both open the one Router |
| 3 | //! setup view (`tui::views::router_setup`) or run a preset through it. |
| 4 | |
| 5 | use crate::commands::traits::{CommandInfo, RegisterCommand}; |
| 6 | use crate::tui::app::{App, AppAction}; |
| 7 | use crate::tui::views::router_setup::parse_router_args; |
| 8 | use codewhale_localization::MessageId; |
| 9 | |
| 10 | use super::CommandResult; |
| 11 | |
| 12 | pub(in crate::commands) const COMMAND_INFO: CommandInfo = CommandInfo { |
| 13 | name: "router", |
| 14 | aliases: &[], |
| 15 | usage: "/router [jev|fast|off|custom|save]", |
| 16 | description_id: MessageId::CmdRouterDescription, |
| 17 | }; |
| 18 | |
| 19 | pub(in crate::commands) struct RouterCmd; |
| 20 | |
| 21 | impl RegisterCommand for RouterCmd { |
| 22 | fn info() -> &'static CommandInfo { |
| 23 | &COMMAND_INFO |
| 24 | } |
| 25 | |
| 26 | fn execute(_app: &mut App, arg: Option<&str>) -> CommandResult { |
| 27 | router_command(arg) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /// Shared by `/router` and `/model router`. |
| 32 | pub(in crate::commands) fn router_command(arg: Option<&str>) -> CommandResult { |
| 33 | match parse_router_args(arg) { |
| 34 | Ok(request) => CommandResult::action(AppAction::RouterSetup { request }), |
| 35 | Err(usage) => CommandResult::error(usage), |
| 36 | } |
| 37 | } |
| 38 |