Skip to content

Commit

Permalink
fix(multicall): Disallow args on multicall binary
Browse files Browse the repository at this point in the history
Set expectations for how this can be used and to make sure the right
errors are given.
  • Loading branch information
epage committed May 2, 2022
1 parent ce727f1 commit f9fdb99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/build/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4027,7 +4027,7 @@ impl<'help> App<'help> {

#[cfg(feature = "unstable-multicall")]
{
if self.is_set(AppSettings::Multicall) {
if self.is_multicall_set() {
self.settings.insert(AppSettings::SubcommandRequired.into());
self.settings.insert(AppSettings::DisableHelpFlag.into());
self.settings.insert(AppSettings::DisableVersionFlag.into());
Expand Down
10 changes: 10 additions & 0 deletions src/build/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ pub(crate) fn assert_app(cmd: &Command) {
for arg in cmd.get_arguments() {
assert_arg(arg);

#[cfg(feature = "unstable-multicall")]
{
assert!(
!cmd.is_multicall_set(),
"Command {}: Arguments like {} cannot be set on a multicall command",
cmd.get_name(),
arg.name
);
}

if let Some(s) = arg.short.as_ref() {
short_flags.push(Flag::Arg(format!("-{}", s), &*arg.name));
}
Expand Down
14 changes: 14 additions & 0 deletions tests/builder/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,17 @@ For more information try help
.unwrap_err();
assert_eq!(err.kind(), ErrorKind::DisplayVersion);
}

#[cfg(feature = "unstable-multicall")]
#[test]
#[should_panic = "Command repl: Arguments like oh-no cannot be set on a multicall command"]
fn cant_have_args_with_multicall() {
let mut cmd = Command::new("repl")
.version("1.0.0")
.propagate_version(true)
.multicall(true)
.subcommand(Command::new("foo"))
.subcommand(Command::new("bar"))
.arg(Arg::new("oh-no"));
cmd.build();
}

0 comments on commit f9fdb99

Please sign in to comment.