@@ -19,46 +19,38 @@ use crate::platform::Context;
1919
2020impl InternalCommand {
2121 /// Validate that the command exists
22- pub fn validate ( & self ) -> Result < ( ) > {
23- // Format a command string
24- let cmd_str = if !self . command . starts_with ( '/' ) {
25- format ! ( "/{}" , self . command)
26- } else {
27- self . command . clone ( )
28- } ;
29-
30- // Try to parse the command using the Command::parse method
31- match Command :: parse ( & cmd_str) {
22+ pub async fn validate ( & self ) -> Result < ( ) > {
23+ // Parse the command using the existing parse_from_components method
24+ match Command :: parse_from_components (
25+ & self . command ,
26+ self . subcommand . as_ref ( ) ,
27+ self . args . as_ref ( ) ,
28+ self . flags . as_ref ( ) ,
29+ ) {
3230 Ok ( _) => Ok ( ( ) ) ,
3331 Err ( e) => Err ( eyre:: eyre!( "Unknown command: {} - {}" , self . command, e) ) ,
3432 }
3533 }
3634
3735 /// Check if the command requires user acceptance
3836 pub fn requires_acceptance ( & self ) -> bool {
39- // Format a command string
40- let cmd_str = if !self . command . starts_with ( '/' ) {
41- format ! ( "/{}" , self . command)
42- } else {
43- self . command . clone ( )
44- } ;
45-
46- // Try to parse the command
47- if let Ok ( command) = Command :: parse ( & cmd_str) {
48- // Get the handler for this command using to_handler()
49- let handler = command. to_handler ( ) ;
50-
51- // Convert args to string slices for the handler
52- let args: Vec < & str > = match & self . subcommand {
53- Some ( subcommand) => vec ! [ subcommand. as_str( ) ] ,
54- None => vec ! [ ] ,
55- } ;
37+ // Parse the command using the existing parse_from_components method
38+ match Command :: parse_from_components (
39+ & self . command ,
40+ self . subcommand . as_ref ( ) ,
41+ self . args . as_ref ( ) ,
42+ self . flags . as_ref ( ) ,
43+ ) {
44+ Ok ( command) => {
45+ // Get the handler directly from the command
46+ // This will automatically use the subcommand's handler when appropriate
47+ let handler = command. to_handler ( ) ;
5648
57- return handler. requires_confirmation ( & args) ;
49+ // Pass empty args since the handler already knows what command it's for
50+ handler. requires_confirmation ( & [ ] )
51+ } ,
52+ Err ( _) => true , // Default to requiring confirmation for unparsable commands
5853 }
59-
60- // For commands not recognized, default to requiring confirmation
61- true
6254 }
6355
6456 /// Format the command string with subcommand and arguments
@@ -98,22 +90,23 @@ impl InternalCommand {
9890
9991 /// Get a description for the command
10092 pub fn get_command_description ( & self ) -> String {
101- // Format a simple command string
102- let cmd_str = if !self . command . starts_with ( '/' ) {
103- format ! ( "/{}" , self . command)
104- } else {
105- self . command . clone ( )
106- } ;
107-
108- // Try to parse the command
109- if let Ok ( command) = Command :: parse ( & cmd_str) {
110- // Get the handler for this command using to_handler()
111- let handler = command. to_handler ( ) ;
112- return handler. description ( ) . to_string ( ) ;
93+ // Parse the command using the existing parse_from_components method
94+ match Command :: parse_from_components (
95+ & self . command ,
96+ self . subcommand . as_ref ( ) ,
97+ self . args . as_ref ( ) ,
98+ self . flags . as_ref ( ) ,
99+ ) {
100+ Ok ( command) => {
101+ // Get the handler for this command using to_handler()
102+ let handler = command. to_handler ( ) ;
103+ handler. description ( ) . to_string ( )
104+ } ,
105+ Err ( _) => {
106+ // For commands not recognized, return a generic description
107+ "Execute a command in the Q chat system" . to_string ( )
108+ } ,
113109 }
114-
115- // For commands not recognized, return a generic description
116- "Execute a command in the Q chat system" . to_string ( )
117110 }
118111
119112 /// Queue description for the command execution
0 commit comments