@@ -21,12 +21,18 @@ pub mod signer;
21
21
since = "1.17.0" ,
22
22
note = "Please use the functions in `solana_clap_v3_utils::input_parsers::signer` directly instead"
23
23
) ]
24
+ #[ allow( deprecated) ]
24
25
pub use signer:: {
25
26
pubkey_of_signer, pubkeys_of_multiple_signers, pubkeys_sigs_of, resolve_signer, signer_of,
26
27
STDOUT_OUTFILE_TOKEN ,
27
28
} ;
28
29
29
30
// Return parsed values from matches at `name`
31
+ #[ deprecated(
32
+ since = "2.0.0" ,
33
+ note = "Please use the functions `ArgMatches::get_many` or `ArgMatches::try_get_many` instead"
34
+ ) ]
35
+ #[ allow( deprecated) ]
30
36
pub fn values_of < T > ( matches : & ArgMatches , name : & str ) -> Option < Vec < T > >
31
37
where
32
38
T : std:: str:: FromStr ,
38
44
}
39
45
40
46
// Return a parsed value from matches at `name`
47
+ #[ deprecated(
48
+ since = "2.0.0" ,
49
+ note = "Please use the functions `ArgMatches::get_one` or `ArgMatches::try_get_one` instead"
50
+ ) ]
51
+ #[ allow( deprecated) ]
41
52
pub fn value_of < T > ( matches : & ArgMatches , name : & str ) -> Option < T >
42
53
where
43
54
T : std:: str:: FromStr ,
48
59
. and_then ( |value| value. parse :: < T > ( ) . ok ( ) )
49
60
}
50
61
62
+ #[ deprecated(
63
+ since = "2.0.0" ,
64
+ note = "Please use `ArgMatches::get_one::<UnixTimestamp>(...)` instead"
65
+ ) ]
66
+ #[ allow( deprecated) ]
51
67
pub fn unix_timestamp_from_rfc3339_datetime (
52
68
matches : & ArgMatches ,
53
69
name : & str ,
@@ -63,14 +79,25 @@ pub fn unix_timestamp_from_rfc3339_datetime(
63
79
since = "1.17.0" ,
64
80
note = "please use `Amount::parse_decimal` and `Amount::sol_to_lamport` instead"
65
81
) ]
82
+ #[ allow( deprecated) ]
66
83
pub fn lamports_of_sol ( matches : & ArgMatches , name : & str ) -> Option < u64 > {
67
84
value_of ( matches, name) . map ( sol_to_lamports)
68
85
}
69
86
87
+ #[ deprecated(
88
+ since = "2.0.0" ,
89
+ note = "Please use `ArgMatches::get_one::<ClusterType>(...)` instead"
90
+ ) ]
91
+ #[ allow( deprecated) ]
70
92
pub fn cluster_type_of ( matches : & ArgMatches , name : & str ) -> Option < ClusterType > {
71
93
value_of ( matches, name)
72
94
}
73
95
96
+ #[ deprecated(
97
+ since = "2.0.0" ,
98
+ note = "Please use `ArgMatches::get_one::<CommitmentConfig>(...)` instead"
99
+ ) ]
100
+ #[ allow( deprecated) ]
74
101
pub fn commitment_of ( matches : & ArgMatches , name : & str ) -> Option < CommitmentConfig > {
75
102
matches
76
103
. value_of ( name)
@@ -246,6 +273,11 @@ pub fn parse_derived_address_seed(arg: &str) -> Result<String, String> {
246
273
}
247
274
248
275
// Return the keypair for an argument with filename `name` or None if not present.
276
+ #[ deprecated(
277
+ since = "2.0.0" ,
278
+ note = "Please use `input_parsers::signer::try_keypair_of` instead"
279
+ ) ]
280
+ #[ allow( deprecated) ]
249
281
pub fn keypair_of ( matches : & ArgMatches , name : & str ) -> Option < Keypair > {
250
282
if let Some ( value) = matches. value_of ( name) {
251
283
if value == ASK_KEYWORD {
@@ -259,6 +291,11 @@ pub fn keypair_of(matches: &ArgMatches, name: &str) -> Option<Keypair> {
259
291
}
260
292
}
261
293
294
+ #[ deprecated(
295
+ since = "2.0.0" ,
296
+ note = "Please use `input_parsers::signer::try_keypairs_of` instead"
297
+ ) ]
298
+ #[ allow( deprecated) ]
262
299
pub fn keypairs_of ( matches : & ArgMatches , name : & str ) -> Option < Vec < Keypair > > {
263
300
matches. values_of ( name) . map ( |values| {
264
301
values
@@ -276,10 +313,20 @@ pub fn keypairs_of(matches: &ArgMatches, name: &str) -> Option<Vec<Keypair>> {
276
313
277
314
// Return a pubkey for an argument that can itself be parsed into a pubkey,
278
315
// or is a filename that can be read as a keypair
316
+ #[ deprecated(
317
+ since = "2.0.0" ,
318
+ note = "Please use `input_parsers::signer::try_pubkey_of` instead"
319
+ ) ]
320
+ #[ allow( deprecated) ]
279
321
pub fn pubkey_of ( matches : & ArgMatches , name : & str ) -> Option < Pubkey > {
280
322
value_of ( matches, name) . or_else ( || keypair_of ( matches, name) . map ( |keypair| keypair. pubkey ( ) ) )
281
323
}
282
324
325
+ #[ deprecated(
326
+ since = "2.0.0" ,
327
+ note = "Please use `input_parsers::signer::try_pubkeys_of` instead"
328
+ ) ]
329
+ #[ allow( deprecated) ]
283
330
pub fn pubkeys_of ( matches : & ArgMatches , name : & str ) -> Option < Vec < Pubkey > > {
284
331
matches. values_of ( name) . map ( |values| {
285
332
values
@@ -294,12 +341,13 @@ pub fn pubkeys_of(matches: &ArgMatches, name: &str) -> Option<Vec<Pubkey>> {
294
341
} )
295
342
}
296
343
344
+ #[ allow( deprecated) ]
297
345
#[ cfg( test) ]
298
346
mod tests {
299
347
use {
300
348
super :: * ,
301
- clap:: { Arg , Command } ,
302
- solana_sdk:: { hash:: Hash , pubkey:: Pubkey } ,
349
+ clap:: { Arg , ArgAction , Command } ,
350
+ solana_sdk:: { commitment_config :: CommitmentLevel , hash:: Hash , pubkey:: Pubkey } ,
303
351
} ;
304
352
305
353
fn app < ' ab > ( ) -> Command < ' ab > {
@@ -308,7 +356,7 @@ mod tests {
308
356
Arg :: new ( "multiple" )
309
357
. long ( "multiple" )
310
358
. takes_value ( true )
311
- . multiple_occurrences ( true )
359
+ . action ( ArgAction :: Append )
312
360
. multiple_values ( true ) ,
313
361
)
314
362
. arg ( Arg :: new ( "single" ) . takes_value ( true ) . long ( "single" ) )
@@ -545,4 +593,87 @@ mod tests {
545
593
}
546
594
}
547
595
}
596
+
597
+ #[ test]
598
+ fn test_unix_timestamp_from_rfc3339_datetime ( ) {
599
+ let command = Command :: new ( "test" ) . arg (
600
+ Arg :: new ( "timestamp" )
601
+ . long ( "timestamp" )
602
+ . takes_value ( true )
603
+ . value_parser ( clap:: value_parser!( UnixTimestamp ) ) ,
604
+ ) ;
605
+
606
+ // success case
607
+ let matches = command
608
+ . clone ( )
609
+ . try_get_matches_from ( vec ! [ "test" , "--timestamp" , "1234" ] )
610
+ . unwrap ( ) ;
611
+ assert_eq ! (
612
+ * matches. get_one:: <UnixTimestamp >( "timestamp" ) . unwrap( ) ,
613
+ 1234 ,
614
+ ) ;
615
+
616
+ // validation fails
617
+ let matches_error = command
618
+ . clone ( )
619
+ . try_get_matches_from ( vec ! [ "test" , "--timestamp" , "this_is_an_invalid_arg" ] )
620
+ . unwrap_err ( ) ;
621
+ assert_eq ! ( matches_error. kind, clap:: error:: ErrorKind :: ValueValidation ) ;
622
+ }
623
+
624
+ #[ test]
625
+ fn test_cluster_type ( ) {
626
+ let command = Command :: new ( "test" ) . arg (
627
+ Arg :: new ( "cluster" )
628
+ . long ( "cluster" )
629
+ . takes_value ( true )
630
+ . value_parser ( clap:: value_parser!( ClusterType ) ) ,
631
+ ) ;
632
+
633
+ // success case
634
+ let matches = command
635
+ . clone ( )
636
+ . try_get_matches_from ( vec ! [ "test" , "--cluster" , "testnet" ] )
637
+ . unwrap ( ) ;
638
+ assert_eq ! (
639
+ * matches. get_one:: <ClusterType >( "cluster" ) . unwrap( ) ,
640
+ ClusterType :: Testnet
641
+ ) ;
642
+
643
+ // validation fails
644
+ let matches_error = command
645
+ . clone ( )
646
+ . try_get_matches_from ( vec ! [ "test" , "--cluster" , "this_is_an_invalid_arg" ] )
647
+ . unwrap_err ( ) ;
648
+ assert_eq ! ( matches_error. kind, clap:: error:: ErrorKind :: ValueValidation ) ;
649
+ }
650
+
651
+ #[ test]
652
+ fn test_commitment_config ( ) {
653
+ let command = Command :: new ( "test" ) . arg (
654
+ Arg :: new ( "commitment" )
655
+ . long ( "commitment" )
656
+ . takes_value ( true )
657
+ . value_parser ( clap:: value_parser!( CommitmentConfig ) ) ,
658
+ ) ;
659
+
660
+ // success case
661
+ let matches = command
662
+ . clone ( )
663
+ . try_get_matches_from ( vec ! [ "test" , "--commitment" , "finalized" ] )
664
+ . unwrap ( ) ;
665
+ assert_eq ! (
666
+ * matches. get_one:: <CommitmentConfig >( "commitment" ) . unwrap( ) ,
667
+ CommitmentConfig {
668
+ commitment: CommitmentLevel :: Finalized
669
+ } ,
670
+ ) ;
671
+
672
+ // validation fails
673
+ let matches_error = command
674
+ . clone ( )
675
+ . try_get_matches_from ( vec ! [ "test" , "--commitment" , "this_is_an_invalid_arg" ] )
676
+ . unwrap_err ( ) ;
677
+ assert_eq ! ( matches_error. kind, clap:: error:: ErrorKind :: ValueValidation ) ;
678
+ }
548
679
}
0 commit comments