22#![ allow( unused) ]
33
44use {
5- crate :: config:: Config , // Added
5+ crate :: config:: Config ,
66 crate :: utils:: diagnostics:: DiagnosticCoordinator ,
77 crate :: utils:: { dashboard, ebpf_deploy, examples, nodes, ssh_deploy, svm_info} ,
8+ crate :: utils:: markdown_renderer:: MarkdownRenderer ,
89 clparse:: parse_command_line,
910 solana_client:: rpc_client:: RpcClient ,
10- solana_sdk:: { native_token:: Sol , pubkey:: Pubkey , signature:: Signer } , // Modified (removed CommitmentConfig) - bad formatting
11- std:: { process:: exit, str:: FromStr } , // Modified
11+ solana_sdk:: {
12+ native_token:: Sol ,
13+ pubkey:: Pubkey ,
14+ signature:: Signer
15+ } ,
16+ std:: { process:: exit, str:: FromStr } ,
1217} ;
1318
1419// Helper function to handle the type mismatch between clap v2 and v4
@@ -56,22 +61,30 @@ async fn handle_ai_query(
5661 sub_matches : & clap:: ArgMatches ,
5762 app_matches : & clap:: ArgMatches ,
5863) -> Result < ( ) , Box < dyn std:: error:: Error > > {
59- // For external subcommands, clap provides the additional arguments differently
60- // We need to collect them from the raw args since clap doesn't know about them
61- let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
62-
63- // Find where our subcommand starts and collect everything after osvm
64- let mut query_parts = Vec :: new ( ) ;
65- let mut found_osvm = false ;
66-
67- for arg in args. iter ( ) . skip ( 1 ) {
68- // Skip the binary name
69- if !found_osvm {
70- found_osvm = true ;
71- }
72- // Skip global flags like --help, --version, etc.
73- if !arg. starts_with ( '-' ) {
74- query_parts. push ( arg. clone ( ) ) ;
64+ // For external subcommands, clap collects additional arguments in subcommand_value
65+ // This is the proper way to handle external subcommands with clap
66+ let mut query_parts = vec ! [ sub_command. to_string( ) ] ;
67+
68+ // Get additional arguments from clap's external subcommand handling
69+ if let Some ( external_args) = sub_matches. get_many :: < String > ( "" ) {
70+ query_parts. extend ( external_args. cloned ( ) ) ;
71+ }
72+
73+ // If clap doesn't provide args (fallback), parse from environment
74+ // This maintains compatibility while documenting the limitation
75+ if query_parts. len ( ) == 1 {
76+ let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
77+
78+ // Collect non-flag arguments starting from the subcommand
79+ let mut found_subcommand = false ;
80+ for arg in args. iter ( ) . skip ( 1 ) {
81+ if found_subcommand {
82+ if !arg. starts_with ( '-' ) {
83+ query_parts. push ( arg. clone ( ) ) ;
84+ }
85+ } else if arg == sub_command {
86+ found_subcommand = true ;
87+ }
7588 }
7689 }
7790
@@ -91,7 +104,9 @@ async fn handle_ai_query(
91104 if debug_mode {
92105 println ! ( "🤖 AI Response:" ) ;
93106 }
94- println ! ( "{}" , response) ;
107+ // Render the response as markdown for better formatting
108+ let renderer = MarkdownRenderer :: new ( ) ;
109+ renderer. render ( & response) ;
95110 }
96111 Err ( e) => {
97112 eprintln ! ( "❌ AI query failed: {}" , e) ;
0 commit comments