Skip to content

Commit 5f40460

Browse files
committed
abstract
1 parent ec020b9 commit 5f40460

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

codex-rs/tui/src/slash_command.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ use once_cell::sync::Lazy;
22
use std::collections::HashMap;
33
use strum_macros::AsRefStr;
44
use strum_macros::EnumIter;
5-
use strum_macros::EnumString;
65
use strum_macros::IntoStaticStr;
76

87
/// Commands that can be invoked by starting a message with a leading slash.
9-
#[derive(
10-
Debug, Clone, Copy, PartialEq, Eq, Hash, EnumString, EnumIter, AsRefStr, IntoStaticStr,
11-
)]
8+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, AsRefStr, IntoStaticStr)]
129
#[strum(serialize_all = "kebab-case")]
1310
pub enum SlashCommand {
1411
// DO NOT ALPHA-SORT! Enum order is presentation order in the popup, so
@@ -25,7 +22,6 @@ pub enum SlashCommand {
2522
Status,
2623
Mcp,
2724
Logout,
28-
#[strum(serialize = "exit", serialize = "e")]
2925
Quit,
3026
Feedback,
3127
#[cfg(debug_assertions)]
@@ -84,6 +80,14 @@ pub fn resolve_slash_command(name: &str) -> Option<SlashCommand> {
8480
NAME_TO_CMD.get(name).copied()
8581
}
8682

83+
impl std::str::FromStr for SlashCommand {
84+
type Err = ();
85+
86+
fn from_str(s: &str) -> Result<Self, Self::Err> {
87+
NAME_TO_CMD.get(s).copied().ok_or(())
88+
}
89+
}
90+
8791
/// Central spec for all slash commands. Keeps metadata in one place.
8892
struct CommandSpec {
8993
cmd: SlashCommand,

0 commit comments

Comments
 (0)