Skip to content

Commit

Permalink
Checks & stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Apr 16, 2020
1 parent 3d6c854 commit 5d2a6dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion clap_generate/examples/value_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 15 additions & 1 deletion src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/build/arg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
}
}

Expand Down

0 comments on commit 5d2a6dc

Please sign in to comment.