@@ -77,7 +77,9 @@ export match;
77
77
export fail_;
78
78
export fail_str;
79
79
export opt_present;
80
+ export opts_present;
80
81
export opt_str;
82
+ export opts_str;
81
83
export opt_strs;
82
84
export opt_maybe_str;
83
85
export opt_default;
@@ -292,6 +294,18 @@ fn opt_present(m: match, nm: str) -> bool {
292
294
ret vec:: len :: < optval > ( opt_vals ( m, nm) ) > 0 u;
293
295
}
294
296
297
+ #[ doc = "Returns true if any of several options were matched" ]
298
+ fn opts_present ( m : match , names : [ str ] ) -> bool {
299
+ for vec:: each( names) { |nm|
300
+ alt find_opt( m. opts, mkname( nm) ) {
301
+ some( _) { ret true ; }
302
+ _ { }
303
+ }
304
+ }
305
+ ret false;
306
+ }
307
+
308
+
295
309
#[ doc = "
296
310
Returns the string argument supplied to a matching option
297
311
@@ -301,6 +315,23 @@ fn opt_str(m: match, nm: str) -> str {
301
315
ret alt opt_val ( m, nm) { val ( s) { s } _ { fail } } ;
302
316
}
303
317
318
+ #[ doc = "
319
+ Returns the string argument supplied to one of several matching options
320
+
321
+ Fails if the no option was provided from the given list, or if the no such
322
+ option took an argument
323
+ " ]
324
+ fn opts_str ( m : match , names : [ str ] ) -> str {
325
+ for vec:: each( names) { |nm|
326
+ alt opt_val( m, nm) {
327
+ val( s) { ret s }
328
+ _ { }
329
+ }
330
+ }
331
+ fail;
332
+ }
333
+
334
+
304
335
#[ doc = "
305
336
Returns a vector of the arguments provided to all matches of the given option.
306
337
@@ -805,6 +836,26 @@ mod tests {
805
836
}
806
837
}
807
838
839
+ #[ test]
840
+ fn test_multi( ) {
841
+ let args = [ "-e" , "foo" , "--encrypt" , "foo" ] ;
842
+ let opts = [ optopt ( "e" ) , optopt ( "encrypt" ) ] ;
843
+ let match = alt getopts ( args, opts) {
844
+ result:: ok ( m) { m }
845
+ result:: err ( f) { fail; }
846
+ } ;
847
+ assert opts_present( match , [ "e" ] ) ;
848
+ assert opts_present( match , [ "encrypt" ] ) ;
849
+ assert opts_present( match , [ "encrypt" , "e" ] ) ;
850
+ assert opts_present( match , [ "e" , "encrypt" ] ) ;
851
+ assert ! opts_present( match , [ "thing" ] ) ;
852
+ assert ! opts_present( match , [ ] ) ;
853
+
854
+ assert opts_str( match , [ "e" ] ) == "foo" ;
855
+ assert opts_str( match , [ "encrypt" ] ) == "foo" ;
856
+ assert opts_str( match , [ "e" , "encrypt" ] ) == "foo" ;
857
+ assert opts_str( match , [ "encrypt" , "e" ] ) == "foo" ;
858
+ }
808
859
}
809
860
810
861
// Local Variables:
0 commit comments