@@ -66,22 +66,18 @@ pub struct CliHandler {
6666}
6767
6868impl CliHandler {
69+ /// Creates a new `CliHandler` instance from command-line arguments.
70+ ///
71+ /// # Configuration Loading
72+ /// 1. If `args.config_file` is specified, loads from that file
73+ /// 2. Otherwise, loads from the default Solana CLI config file
6974 pub async fn from_args( args : & Args ) -> Result < Self > {
70- let rpc_url = args. rpc_url . clone ( ) ;
7175 CommitmentConfig :: confirmed ( ) ;
72-
7376 let commitment = CommitmentConfig :: from_str ( & args. commitment ) ?;
7477
75- let keypair = match & args. config_file {
76- Some ( config_file) => {
77- let config = Config :: load ( config_file. as_os_str ( ) . to_str ( ) . unwrap ( ) ) ?;
78- let keypair_path = match & args. keypair_path {
79- Some ( path) => path. as_str ( ) ,
80- None => config. keypair_path . as_str ( ) ,
81- } ;
82- read_keypair_file ( keypair_path)
83- . map_err ( |e| anyhow ! ( "Failed to read keypair path: {e:?}" ) ) ?
84- }
78+ // Load config - either from specified file or default
79+ let config = match & args. config_file {
80+ Some ( config_file) => Config :: load ( config_file. as_os_str ( ) . to_str ( ) . unwrap ( ) ) ?,
8581 None => {
8682 let config_file = solana_cli_config:: CONFIG_FILE
8783 . as_ref ( )
@@ -91,10 +87,15 @@ impl CliHandler {
9187 . map_err ( |e| anyhow ! ( "Failed to read keypair path: {e:?}" ) ) ?,
9288 Err ( _) => read_keypair_file ( args. keypair_path . clone ( ) . unwrap ( ) )
9389 . map_err ( |e| anyhow ! ( "Failed to read keypair path: {e:?}" ) ) ?,
94- }
9590 }
9691 } ;
9792
93+ let keypair_path = args. keypair_path . as_deref ( ) . unwrap_or ( & config. keypair_path ) ;
94+ let keypair = read_keypair_file ( keypair_path)
95+ . map_err ( |e| anyhow ! ( "Failed to read keypair path: {e:?}" ) ) ?;
96+
97+ let rpc_url = args. rpc_url . clone ( ) . unwrap_or ( config. json_rpc_url ) ;
98+
9899 let restaking_program_id = Pubkey :: from_str ( & args. restaking_program_id ) ?;
99100 let vault_program_id = Pubkey :: from_str ( & args. vault_program_id ) ?;
100101 let tip_router_program_id = Pubkey :: from_str ( & args. tip_router_program_id ) ?;
0 commit comments