@@ -1891,18 +1891,48 @@ impl<'a, 'b> Arg<'a, 'b> {
1891
1891
/// **WARNING:**
1892
1892
///
1893
1893
/// Setting `multiple(true)` for an [option] with no other details, allows multiple values
1894
- /// **and** multiple occurrences because it isn't possible to have more occurrences than values for
1895
- /// options. Because multiple values are allowed, `--option val1 val2 val3` is perfectly valid,
1896
- /// be careful when designing a CLI where positional arguments are expected after a option which
1897
- /// accepts multiple values, as `clap` will continue parsing *values* until it reaches the max
1898
- /// or specific number of values defined, or another flag or option.
1894
+ /// **and** multiple occurrences because it isn't possible to have more occurrences than values
1895
+ /// for options. Because multiple values are allowed, `--option val1 val2 val3` is perfectly
1896
+ /// valid, be careful when designing a CLI where positional arguments are expected after a
1897
+ /// option which accepts multiple values, as `clap` will continue parsing *values* until it
1898
+ /// reaches the max or specific number of values defined, or another flag or option.
1899
1899
///
1900
1900
/// **Pro Tip**:
1901
1901
///
1902
1902
/// It's possible to define an option which allows multiple occurrences, but only one value per
1903
1903
/// occurrence. To do this use [`Arg::number_of_values(1)`] in coordination with
1904
1904
/// [`Arg::multiple(true)`].
1905
1905
///
1906
+ /// **WARNING:**
1907
+ ///
1908
+ /// When using args with `multiple(true)` on [options] or [positionals] (i.e. those args that
1909
+ /// accept values) and [subcommands], one needs to consider the posibility of an argument value
1910
+ /// being the same as a valid subcommand. By default `clap` will parse the argument in question
1911
+ /// as a value *only if* a value is possible at that moment. Otherwise it will be parsed as a
1912
+ /// subcommand. In effect, this means using `multiple(true)` with no additional parameters and
1913
+ /// a possible value that coincides with a subcommand name, the subcommand cannot be called
1914
+ /// unless another argument is passed first.
1915
+ ///
1916
+ /// As an example, consider a CLI with an option `--ui-paths=<paths>...` and subcommand `signer`
1917
+ ///
1918
+ /// The following would be parsed as values to `--ui-paths`.
1919
+ ///
1920
+ /// ```notrust
1921
+ /// $ program --ui-paths path1 path2 signer
1922
+ /// ```
1923
+ ///
1924
+ /// This is because `--ui-paths` accepts multiple values. `clap` will continue parsing values
1925
+ /// until another argument is reached and it knows `--ui-paths` is done.
1926
+ ///
1927
+ /// By adding additional parameters to `--ui-paths` we can solve this issue. Consider adding
1928
+ /// [`Arg::number_of_values(1)`] as discussed above. The following are all valid, and `signer`
1929
+ /// is parsed as both a subcommand and a value in the second case.
1930
+ ///
1931
+ /// ```notrust
1932
+ /// $ program --ui-paths path1 signer
1933
+ /// $ program --ui-paths path1 --ui-paths signer signer
1934
+ /// ```
1935
+ ///
1906
1936
/// # Examples
1907
1937
///
1908
1938
/// ```rust
@@ -2036,6 +2066,9 @@ impl<'a, 'b> Arg<'a, 'b> {
2036
2066
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
2037
2067
/// ```
2038
2068
/// [option]: ./struct.Arg.html#method.takes_value
2069
+ /// [options]: ./struct.Arg.html#method.takes_value
2070
+ /// [subcommands]: ./struct.SubCommand.html
2071
+ /// [positionals]: ./struct.Arg.html#method.index
2039
2072
/// [`Arg::number_of_values(1)`]: ./struct.Arg.html#method.number_of_values
2040
2073
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
2041
2074
pub fn multiple ( self , multi : bool ) -> Self {
0 commit comments