@@ -90,6 +90,9 @@ pub struct Arg<'a, 'b> where 'a: 'b {
90
90
pub overrides : Option < Vec < & ' a str > > ,
91
91
#[ doc( hidden) ]
92
92
pub settings : ArgFlags ,
93
+ // Delimiting character for value separation
94
+ #[ doc( hidden) ]
95
+ pub val_delim : Option < char > ,
93
96
}
94
97
95
98
impl < ' a , ' b > Default for Arg < ' a , ' b > {
@@ -111,6 +114,7 @@ impl<'a, 'b> Default for Arg<'a, 'b> {
111
114
validator : None ,
112
115
overrides : None ,
113
116
settings : ArgFlags :: new ( ) ,
117
+ val_delim : Some ( ',' ) ,
114
118
}
115
119
}
116
120
}
@@ -175,6 +179,7 @@ impl<'a, 'b> Arg<'a, 'b> {
175
179
"max_values" => a. max_values ( v. as_i64 ( ) . unwrap ( ) as u8 ) ,
176
180
"min_values" => a. min_values ( v. as_i64 ( ) . unwrap ( ) as u8 ) ,
177
181
"value_name" => a. value_name ( v. as_str ( ) . unwrap ( ) ) ,
182
+ "value_delimiter" => a. value_delimiter ( v. as_str ( ) . unwrap ( ) ) ,
178
183
"value_names" => {
179
184
for ys in v. as_vec ( ) . unwrap ( ) {
180
185
if let Some ( s) = ys. as_str ( ) {
@@ -199,10 +204,10 @@ impl<'a, 'b> Arg<'a, 'b> {
199
204
}
200
205
a
201
206
}
202
- "mutually_overrides_with " => {
207
+ "overrides_with " => {
203
208
for ys in v. as_vec ( ) . unwrap ( ) {
204
209
if let Some ( s) = ys. as_str ( ) {
205
- a = a. mutually_overrides_with ( s) ;
210
+ a = a. overrides_with ( s) ;
206
211
}
207
212
}
208
213
a
@@ -430,9 +435,9 @@ impl<'a, 'b> Arg<'a, 'b> {
430
435
/// ```no_run
431
436
/// # use clap::{App, Arg};
432
437
/// # let myprog = App::new("myprog").arg(Arg::with_name("config")
433
- /// .mutually_overrides_with ("debug")
438
+ /// .overrides_with ("debug")
434
439
/// # ).get_matches();
435
- pub fn mutually_overrides_with ( mut self , name : & ' a str ) -> Self {
440
+ pub fn overrides_with ( mut self , name : & ' a str ) -> Self {
436
441
if let Some ( ref mut vec) = self . overrides {
437
442
vec. push ( name. as_ref ( ) ) ;
438
443
} else {
@@ -450,9 +455,9 @@ impl<'a, 'b> Arg<'a, 'b> {
450
455
/// # use clap::{App, Arg};
451
456
/// let config_overrides = ["debug", "input"];
452
457
/// # let myprog = App::new("myprog").arg(Arg::with_name("config")
453
- /// .mutually_overrides_with_all (&config_overrides)
458
+ /// .overrides_with_all (&config_overrides)
454
459
/// # ).get_matches();
455
- pub fn mutually_overrides_with_all ( mut self , names : & [ & ' a str ] ) -> Self {
460
+ pub fn overrides_with_all ( mut self , names : & [ & ' a str ] ) -> Self {
456
461
if let Some ( ref mut vec) = self . overrides {
457
462
for s in names {
458
463
vec. push ( s) ;
@@ -810,31 +815,57 @@ impl<'a, 'b> Arg<'a, 'b> {
810
815
self
811
816
}
812
817
818
+ /// Specifies the separator to use when values are clumped together, defaults to `,` (comma).
819
+ ///
820
+ /// **NOTE:** implicitly sets `Arg::takes_value(true)`
821
+ ///
822
+ /// # Examples
823
+ ///
824
+ /// ```no_run
825
+ /// # use clap::{App, Arg};
826
+ /// let app = App::new("fake")
827
+ /// .arg(Arg::with_name("config")
828
+ /// .short("c")
829
+ /// .long("config")
830
+ /// .value_delimiter(";"));
831
+ ///
832
+ /// let m = app.get_matches_from(vec![
833
+ /// "fake", "--config=val1;val2;val3"
834
+ /// ]);
835
+ ///
836
+ /// assert_eq!(m.values_of("config").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"])
837
+ /// ```
838
+ pub fn value_delimiter ( mut self , d : & str ) -> Self {
839
+ self = self . set ( ArgSettings :: TakesValue ) ;
840
+ self . val_delim = Some ( d. chars ( )
841
+ . nth ( 0 )
842
+ . expect ( "Failed to get value_delimiter from arg" ) ) ;
843
+ self
844
+ }
845
+
813
846
/// Specifies names for values of option arguments. These names are cosmetic only, used for
814
847
/// help and usage strings only. The names are **not** used to access arguments. The values of
815
848
/// the arguments are accessed in numeric order (i.e. if you specify two names `one` and `two`
816
849
/// `one` will be the first matched value, `two` will be the second).
817
850
///
818
- /// **NOTE:** This implicitly sets `.number_of_values()` so there is no need to set that, but
819
- /// be aware that the number of "names" you set for the values, will be the *exact* number of
820
- /// values required to satisfy this argument
851
+ /// **NOTE:** This implicitly sets `.number_of_values()`, but be aware that the number of
852
+ /// "names" you set for the values, will be the *exact* number of values required to satisfy
853
+ /// this argument
821
854
///
822
- /// **NOTE:** Does *not* require `.multiple (true)` to be set. Setting `.multiple(true)` would
823
- /// allow `-f <file> <file> <file> -f <file> <file> <file>` where as *not* setting
824
- /// `.multiple(true)` would only allow one occurrence of this argument .
855
+ /// **NOTE:** implicitly sets `Arg::takes_value (true)`
856
+ ///
857
+ /// **NOTE:** Does *not* require or imply `.multiple(true)`.
825
858
///
826
859
/// # Examples
827
860
///
828
861
/// ```no_run
829
862
/// # use clap::{App, Arg};
830
- /// let val_names = ["one", "two"];
831
- /// # let matches = App::new("myprog")
832
- /// # .arg(
833
- /// # Arg::with_name("debug").index(1)
834
- /// // ...
835
- /// .value_names(&val_names)
836
- /// # ).get_matches();
863
+ /// Arg::with_name("speed")
864
+ /// .short("s")
865
+ /// .value_names(&["fast", "slow"])
866
+ /// # ;
837
867
pub fn value_names ( mut self , names : & [ & ' b str ] ) -> Self {
868
+ self . setb ( ArgSettings :: TakesValue ) ;
838
869
if let Some ( ref mut vals) = self . val_names {
839
870
let mut l = vals. len ( ) ;
840
871
for s in names {
@@ -878,20 +909,21 @@ impl<'a, 'b> Arg<'a, 'b> {
878
909
self
879
910
}
880
911
881
- /// Specifies the name for value of option or positional arguments. This name is cosmetic only,
882
- /// used for help and usage strings. The name is **not** used to access arguments.
912
+ /// Specifies the name for value of option or positional arguments inside of help documenation.
913
+ /// This name is cosmetic only, the name is **not** used to access arguments.
914
+ ///
915
+ /// **NOTE:** implicitly sets `Arg::takes_value(true)`
883
916
///
884
917
/// # Examples
885
918
///
886
919
/// ```no_run
887
920
/// # use clap::{App, Arg};
888
- /// # let matches = App::new("myprog")
889
- /// # .arg(
890
- /// Arg::with_name("debug")
921
+ /// Arg::with_name("input")
891
922
/// .index(1)
892
- /// .value_name("file ")
893
- /// # ).get_matches() ;
923
+ /// .value_name("FILE ")
924
+ /// # ;
894
925
pub fn value_name ( mut self , name : & ' b str ) -> Self {
926
+ self . setb ( ArgSettings :: TakesValue ) ;
895
927
if let Some ( ref mut vals) = self . val_names {
896
928
let l = vals. len ( ) ;
897
929
vals. insert ( l, name) ;
@@ -924,6 +956,7 @@ impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>>
924
956
validator : a. validator . clone ( ) ,
925
957
overrides : a. overrides . clone ( ) ,
926
958
settings : a. settings . clone ( ) ,
959
+ val_delim : a. val_delim ,
927
960
}
928
961
}
929
962
}
0 commit comments