Files
codex/codex-rs/tui/src/slash_command_invocation.rs
T
Charles CunninghamandCodex b231db7dfa tui: centralize slash command serialization
Introduce a small slash command invocation serializer and consolidate built-in command metadata behind a single spec table without changing slash command runtime behavior.

Co-authored-by: Codex <noreply@openai.com>
2026-03-16 20:43:16 -07:00

41 lines
1.0 KiB
Rust

use crate::slash_command::SlashCommand;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct SlashCommandInvocation {
command: SlashCommand,
args: Vec<String>,
}
impl SlashCommandInvocation {
pub(crate) fn bare(command: SlashCommand) -> Self {
Self {
command,
args: Vec::new(),
}
}
pub(crate) fn into_prefixed_string(self) -> String {
let command = self.command.command();
let joined = match shlex::try_join(
std::iter::once(command).chain(self.args.iter().map(String::as_str)),
) {
Ok(joined) => joined,
Err(err) => panic!("slash command invocation should serialize: {err}"),
};
format!("/{joined}")
}
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn bare_invocation_serializes_with_leading_slash() {
let invocation = SlashCommandInvocation::bare(SlashCommand::Model);
assert_eq!(invocation.into_prefixed_string(), "/model");
}
}