2626 } ,
2727 token:: ComputeUnitLimit ,
2828 } ,
29- std:: { process:: exit, rc:: Rc , sync:: Arc } ,
29+ std:: { process:: exit, rc:: Rc , str :: FromStr , sync:: Arc } ,
3030} ;
3131
3232type SignersOf = Vec < ( Arc < dyn Signer > , Pubkey ) > ;
@@ -227,11 +227,17 @@ impl<'a> Config<'a> {
227227 OutputFormat :: Display
228228 } ) ;
229229
230- let nonce_account = pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager)
231- . unwrap_or_else ( |e| {
232- eprintln ! ( "error: {}" , e) ;
233- exit ( 1 ) ;
234- } ) ;
230+ let nonce_account = match pubkey_of_signer ( matches, NONCE_ARG . name , wallet_manager) {
231+ Ok ( account) => account,
232+ Err ( e) => {
233+ if e. is :: < clap:: parser:: MatchesError > ( ) {
234+ None
235+ } else {
236+ eprintln ! ( "error: {}" , e) ;
237+ exit ( 1 ) ;
238+ }
239+ }
240+ } ;
235241 let nonce_authority = if nonce_account. is_some ( ) {
236242 let ( nonce_authority, _) = signer_from_path (
237243 matches,
@@ -256,18 +262,28 @@ impl<'a> Config<'a> {
256262 None
257263 } ;
258264
259- let sign_only = matches. is_present ( SIGN_ONLY_ARG . name ) ;
260- let dump_transaction_message = matches. is_present ( DUMP_TRANSACTION_MESSAGE . name ) ;
265+ let sign_only = matches. try_contains_id ( SIGN_ONLY_ARG . name ) . unwrap_or ( false ) ;
266+ let dump_transaction_message = matches
267+ . try_contains_id ( DUMP_TRANSACTION_MESSAGE . name )
268+ . unwrap_or ( false ) ;
269+
270+ let pubkey_from_matches = |name| {
271+ matches
272+ . try_get_one :: < String > ( name)
273+ . ok ( )
274+ . flatten ( )
275+ . and_then ( |pubkey| Pubkey :: from_str ( pubkey) . ok ( ) )
276+ } ;
261277
262278 let default_program_id = spl_token:: id ( ) ;
263279 let ( program_id, restrict_to_program_id) = if matches. is_present ( "program_2022" ) {
264280 ( spl_token_2022:: id ( ) , true )
265- } else if let Some ( program_id) = value_of ( matches , "program_id" ) {
281+ } else if let Some ( program_id) = pubkey_from_matches ( "program_id" ) {
266282 ( program_id, true )
267283 } else if !sign_only {
268- if let Some ( address) = value_of ( matches , "token" )
269- . or_else ( || value_of ( matches , "account" ) )
270- . or_else ( || value_of ( matches , "address" ) )
284+ if let Some ( address) = pubkey_from_matches ( "token" )
285+ . or_else ( || pubkey_from_matches ( "account" ) )
286+ . or_else ( || pubkey_from_matches ( "address" ) )
271287 {
272288 (
273289 rpc_client
@@ -290,7 +306,7 @@ impl<'a> Config<'a> {
290306 && !matches. is_present ( COMPUTE_UNIT_LIMIT_ARG . name )
291307 {
292308 clap:: Error :: with_description (
293- & format ! (
309+ format ! (
294310 "Need to set `{}` if `{}` and `--{}` are set" ,
295311 COMPUTE_UNIT_LIMIT_ARG . long, COMPUTE_UNIT_PRICE_ARG . long, BLOCKHASH_ARG . long,
296312 ) ,
@@ -299,7 +315,12 @@ impl<'a> Config<'a> {
299315 . exit ( ) ;
300316 }
301317
302- let nonce_blockhash = value_of ( matches, BLOCKHASH_ARG . name ) ;
318+ let nonce_blockhash = matches
319+ . try_get_one :: < Hash > ( BLOCKHASH_ARG . name )
320+ . ok ( )
321+ . flatten ( )
322+ . copied ( ) ;
323+
303324 let compute_unit_price = value_of ( matches, COMPUTE_UNIT_PRICE_ARG . name ) ;
304325 let compute_unit_limit = value_of ( matches, COMPUTE_UNIT_LIMIT_ARG . name )
305326 . map ( ComputeUnitLimit :: Static )
@@ -310,6 +331,7 @@ impl<'a> Config<'a> {
310331 ComputeUnitLimit :: Simulated
311332 }
312333 } ) ;
334+
313335 Self {
314336 default_signer,
315337 rpc_client,
0 commit comments