diff --git a/clap_generate/examples/value_hints.rs b/clap_generate/examples/value_hints.rs index e475d2c7a0c3..5389a913c673 100644 --- a/clap_generate/examples/value_hints.rs +++ b/clap_generate/examples/value_hints.rs @@ -69,7 +69,9 @@ fn build_cli() -> App<'static> { .value_hint(ValueHint::CommandString), ) .arg( - Arg::with_name("command_with_args").multiple(true), // .value_hint(ValueHint::CommandWithArguments), + Arg::with_name("command_with_args") + .multiple_values(true) + .value_hint(ValueHint::CommandWithArguments), ) .arg( Arg::with_name("user") diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 76d2aabc48dd..f496e1196ce3 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -25,7 +25,7 @@ use crate::output::{Help, Usage}; use crate::parse::errors::Result as ClapResult; use crate::parse::{ArgMatcher, ArgMatches, Input, Parser}; use crate::util::{Id, Key}; -use crate::INTERNAL_ERROR_MSG; +use crate::{ValueHint, INTERNAL_ERROR_MSG}; // FIXME (@CreepySkeleton): some of this variants are never constructed #[derive(Clone, Debug, PartialEq, Eq)] @@ -1665,6 +1665,20 @@ impl<'b> App<'b> { "Global arguments cannot be required.\n\n\t'{}' is marked as global and required", arg.name ); + + if arg.value_hint == ValueHint::CommandWithArguments { + assert!( + arg.short.is_none() && arg.long.is_none(), + "Argument '{}' has hint CommandWithArguments and must be positional.", + arg.name + ); + + assert!( + self.is_set(AppSettings::TrailingVarArg), + "Positional argument '{}' has hint CommandWithArguments, so App must have TrailingVarArg set.", + arg.name + ); + } } for group in &self.groups { diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index 64aa781f310e..209eb26f4311 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -4208,6 +4208,21 @@ impl<'a> Arg<'a> { self.name, ); } + + if self.value_hint != ValueHint::Unknown { + assert!( + self.is_set(ArgSettings::TakesValue), + "Argument '{}' has value hint but takes no value", + self.name + ); + + if self.value_hint == ValueHint::CommandWithArguments { + assert!( + self.is_set(ArgSettings::MultipleValues), + "Argument '{}' uses hint CommandWithArguments and must accept multiple values", + ) + } + } } }