limit_cli/tui/commands/
builtin.rs1use super::{Command, CommandContext, CommandResult};
6use crate::error::CliError;
7
8pub struct HelpCommand;
10
11impl Command for HelpCommand {
12 fn name(&self) -> &str {
13 "help"
14 }
15
16 fn aliases(&self) -> Vec<&str> {
17 vec!["?", "h"]
18 }
19
20 fn description(&self) -> &str {
21 "Show available commands and usage information"
22 }
23
24 fn usage(&self) -> Vec<&str> {
25 vec!["/help", "/help <command>"]
26 }
27
28 fn execute(&self, args: &str, ctx: &mut CommandContext) -> Result<CommandResult, CliError> {
29 if args.is_empty() {
30 let help_text = "Available commands:\n\
32 /help - Show this help message\n\
33 /clear - Clear chat history\n\
34 /exit - Exit the application\n\
35 /quit - Exit the application\n\
36 /tldr - Enable code analysis for this project\n\
37 /session list - List all sessions\n\
38 /session new - Create a new session\n\
39 /session load <id> - Load a session by ID\n\
40 /share - Copy session to clipboard (markdown)\n\
41 /share md - Export session as markdown file\n\
42 /share json - Export session as JSON file\n\
43 \n\
44 Page Up/Down - Scroll chat history";
45 ctx.add_system_message(help_text.to_string());
46 } else {
47 ctx.add_system_message(format!("Help for command: {}", args));
49 }
50
51 Ok(CommandResult::Continue)
52 }
53}
54
55pub struct ClearCommand;
57
58impl Command for ClearCommand {
59 fn name(&self) -> &str {
60 "clear"
61 }
62
63 fn aliases(&self) -> Vec<&str> {
64 vec!["cls"]
65 }
66
67 fn description(&self) -> &str {
68 "Clear the chat history"
69 }
70
71 fn usage(&self) -> Vec<&str> {
72 vec!["/clear"]
73 }
74
75 fn execute(&self, _args: &str, ctx: &mut CommandContext) -> Result<CommandResult, CliError> {
76 ctx.clear_chat();
77 ctx.add_system_message("Chat cleared".to_string());
78 Ok(CommandResult::ClearChat)
79 }
80}
81
82pub struct ExitCommand;
84
85impl Command for ExitCommand {
86 fn name(&self) -> &str {
87 "exit"
88 }
89
90 fn aliases(&self) -> Vec<&str> {
91 vec!["quit", "q"]
92 }
93
94 fn description(&self) -> &str {
95 "Exit the application"
96 }
97
98 fn usage(&self) -> Vec<&str> {
99 vec!["/exit", "/quit"]
100 }
101
102 fn execute(&self, _args: &str, _ctx: &mut CommandContext) -> Result<CommandResult, CliError> {
103 Ok(CommandResult::Exit)
104 }
105}
106
107#[cfg(test)]
108mod tests {
109 use super::*;
110
111 #[test]
112 fn test_help_command() {
113 assert_eq!(HelpCommand.name(), "help");
114 assert!(HelpCommand.aliases().contains(&"?"));
115 }
116
117 #[test]
118 fn test_clear_command() {
119 assert_eq!(ClearCommand.name(), "clear");
120 assert!(ClearCommand.aliases().contains(&"cls"));
121 }
122
123 #[test]
124 fn test_exit_command() {
125 assert_eq!(ExitCommand.name(), "exit");
126 assert!(ExitCommand.aliases().contains(&"quit"));
127 }
128}