| 1 | //! `/workspace` command. |
| 2 | |
| 3 | use crate::commands::traits::{CommandInfo, RegisterCommand}; |
| 4 | use crate::localization::MessageId; |
| 5 | use crate::tui::app::{App, AppAction}; |
| 6 | |
| 7 | use super::CommandResult; |
| 8 | |
| 9 | pub(in crate::commands) const COMMAND_INFO: CommandInfo = CommandInfo { |
| 10 | name: "workspace", |
| 11 | aliases: &["cwd"], |
| 12 | usage: "/workspace [path|worktrees]", |
| 13 | description_id: MessageId::CmdWorkspaceDescription, |
| 14 | }; |
| 15 | |
| 16 | pub(in crate::commands) struct WorkspaceCmd; |
| 17 | |
| 18 | impl RegisterCommand for WorkspaceCmd { |
| 19 | fn info() -> &'static CommandInfo { |
| 20 | &COMMAND_INFO |
| 21 | } |
| 22 | |
| 23 | fn execute(app: &mut App, arg: Option<&str>) -> CommandResult { |
| 24 | match arg.map(str::trim).filter(|a| !a.is_empty()) { |
| 25 | Some("worktrees" | "worktree" | "wt") => { |
| 26 | CommandResult::action(AppAction::OpenWorktreeManager) |
| 27 | } |
| 28 | other => super::core::workspace_switch(app, other), |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 |