Skip to content

Commit

Permalink
Auto merge of #698 - lqd:cancel_equals_abort, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
cancel = abort

This PR allows patterns to be used in the webhooks command parser, for the sole purpose of accepting `cancel` as an alias to `abort`.

<sub>(this is for `@compiler-errors)</sub>`
  • Loading branch information
bors committed Sep 12, 2023
2 parents 48c666a + ff92dc1 commit fa857ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl Crater {
} else {
default_capabilities_for_target()
};
caps.extend(capabilities.clone().into_iter());
caps.extend(capabilities.clone());

agent::run(
url,
Expand Down
19 changes: 13 additions & 6 deletions src/server/routes/webhooks/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub enum CommandParseError {

macro_rules! generate_parser {
(pub enum $enum:ident {
$($command:expr => $variant:ident($var_struct:ident {
$($command:pat => $variant:ident($var_struct:ident {
$($flag:ident: $type:ty = $name:expr,)*
}))*
_ => $d_variant:ident($d_var_struct:ident {$($d_flag:ident: $d_type:ty = $d_name:expr,)*})
=> $d_variant:ident($d_var_struct:ident {$($d_flag:ident: $d_type:ty = $d_name:expr,)*})
}) => {
use crate::prelude::*;
use std::str::FromStr;
Expand Down Expand Up @@ -128,7 +128,7 @@ generate_parser!(pub enum Command {
requirement: Option<String> = "requirement",
})

"abort" => Abort(AbortArgs {
"abort" | "cancel" => Abort(AbortArgs {
name: Option<String> = "name",
})

Expand All @@ -144,7 +144,7 @@ generate_parser!(pub enum Command {

"reload-acl" => ReloadACL(ReloadACLArgs {})

_ => Edit(EditArgs {
=> Edit(EditArgs {
name: Option<String> = "name",
start: Option<Toolchain> = "start",
end: Option<Toolchain> = "end",
Expand All @@ -169,11 +169,11 @@ mod tests {
arg2: Option<String> = "arg2",
})

"bar" => Bar(BarArgs {
"bar" | "bar-alias" => Bar(BarArgs {
arg3: Option<String> = "arg3",
})

_ => Baz(BazArgs {
=> Baz(BazArgs {
arg4: Option<i32> = "arg4",
})
});
Expand Down Expand Up @@ -201,6 +201,7 @@ mod tests {
})
);
test!("bar", TestCommand::Bar(BarArgs { arg3: None }));
test!("bar-alias", TestCommand::Bar(BarArgs { arg3: None }));
test!("", TestCommand::Baz(BazArgs { arg4: None }));

// Test if args are parsed correctly
Expand Down Expand Up @@ -230,6 +231,12 @@ mod tests {
arg3: Some("foo \" bar".into()),
})
);
test!(
"bar-alias arg3=\"foo \\\" bar\"",
TestCommand::Bar(BarArgs {
arg3: Some("foo \" bar".into()),
})
);
test!("arg4=42", TestCommand::Baz(BazArgs { arg4: Some(42) }));

// Test if invalid args are rejected
Expand Down

0 comments on commit fa857ef

Please sign in to comment.