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} ,
88 crate :: utils:: markdown_renderer:: MarkdownRenderer ,
99 clparse:: parse_command_line,
1010 solana_client:: rpc_client:: RpcClient ,
11- solana_sdk:: { native_token:: Sol , pubkey:: Pubkey , signature:: Signer } , // Modified (removed CommitmentConfig) - bad formatting
12- 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 } ,
1317} ;
1418
1519// Helper function to handle the type mismatch between clap v2 and v4
@@ -57,22 +61,30 @@ async fn handle_ai_query(
5761 sub_matches : & clap:: ArgMatches ,
5862 app_matches : & clap:: ArgMatches ,
5963) -> Result < ( ) , Box < dyn std:: error:: Error > > {
60- // For external subcommands, clap provides the additional arguments differently
61- // We need to collect them from the raw args since clap doesn't know about them
62- let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
63-
64- // Find where our subcommand starts and collect everything after osvm
65- let mut query_parts = Vec :: new ( ) ;
66- let mut found_osvm = false ;
67-
68- for arg in args. iter ( ) . skip ( 1 ) {
69- // Skip the binary name
70- if !found_osvm {
71- found_osvm = true ;
72- }
73- // Skip global flags like --help, --version, etc.
74- if !arg. starts_with ( '-' ) {
75- 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+ }
7688 }
7789 }
7890
@@ -94,11 +106,7 @@ async fn handle_ai_query(
94106 }
95107 // Render the response as markdown for better formatting
96108 let renderer = MarkdownRenderer :: new ( ) ;
97- if let Err ( e) = renderer. render ( & response) {
98- // Fallback to plain text if markdown rendering fails
99- eprintln ! ( "⚠️ Markdown rendering failed: {}" , e) ;
100- println ! ( "{}" , response) ;
101- }
109+ renderer. render ( & response) ;
102110 }
103111 Err ( e) => {
104112 eprintln ! ( "❌ AI query failed: {}" , e) ;
0 commit comments