File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 1
1
use std:: error:: Error ;
2
2
use structopt:: StructOpt ;
3
3
4
+ /// Parse a single key-value pair
4
5
fn parse_key_val < T , U > ( s : & str ) -> Result < ( T , U ) , Box < dyn Error > >
5
6
where
6
7
T : std:: str:: FromStr ,
16
17
17
18
#[ derive( StructOpt , Debug ) ]
18
19
struct Opt {
19
- #[ structopt( short = "D" , parse( try_from_str = parse_key_val) ) ]
20
+ // number_of_values = 1 forces the user to repeat the -D option for each key-value pair:
21
+ // my_program -D a=1 -D b=2
22
+ // Without number_of_values = 1 you can do:
23
+ // my_program -D a=1 b=2
24
+ // but this makes adding an argument after the values impossible:
25
+ // my_program -D a=1 -D b=2 my_input_file
26
+ // becomes invalid.
27
+ #[ structopt( short = "D" , parse( try_from_str = parse_key_val) , number_of_values = 1 ) ]
20
28
defines : Vec < ( String , i32 ) > ,
21
29
}
22
30
You can’t perform that action at this time.
0 commit comments