@@ -5,6 +5,7 @@ use std::sync::Arc;
5
5
use tokio:: sync:: Mutex ;
6
6
7
7
use anyhow:: anyhow;
8
+ use clap:: builder:: TypedValueParser ;
8
9
use clap:: Parser ;
9
10
use log:: LevelFilter ;
10
11
use sim_lib:: {
@@ -22,6 +23,22 @@ pub const ACTIVITY_MULTIPLIER: f64 = 2.0;
22
23
/// Default batch size to flush result data to disk
23
24
const DEFAULT_PRINT_BATCH_SIZE : u32 = 500 ;
24
25
26
+ /// Deserializes a f64 as long as it is positive and greater than 0.
27
+ fn deserialize_f64_greater_than_zero ( x : String ) -> Result < f64 , String > {
28
+ match x. parse :: < f64 > ( ) {
29
+ Ok ( x) => {
30
+ if x > 0.0 {
31
+ Ok ( x)
32
+ } else {
33
+ Err ( format ! (
34
+ "capacity_multiplier must be higher than 0. {x} received."
35
+ ) )
36
+ }
37
+ }
38
+ Err ( e) => Err ( e. to_string ( ) ) ,
39
+ }
40
+ }
41
+
25
42
#[ derive( Parser ) ]
26
43
#[ command( version, about) ]
27
44
struct Cli {
@@ -42,7 +59,7 @@ struct Cli {
42
59
#[ clap( long, short, default_value_t = EXPECTED_PAYMENT_AMOUNT , value_parser = clap:: builder:: RangedU64ValueParser :: <u64 >:: new( ) . range( 1 ..u64 :: MAX ) ) ]
43
60
expected_pmt_amt : u64 ,
44
61
/// Multiplier of the overall network capacity used by the random activity generator
45
- #[ clap( long, short, default_value_t = ACTIVITY_MULTIPLIER ) ]
62
+ #[ clap( long, short, default_value_t = ACTIVITY_MULTIPLIER , value_parser = clap :: builder :: StringValueParser :: new ( ) . try_map ( deserialize_f64_greater_than_zero ) ) ]
46
63
capacity_multiplier : f64 ,
47
64
/// Do not create an output file containing the simulations results
48
65
#[ clap( long, default_value_t = false ) ]
0 commit comments