Allow using - and @ in any order (#1063)

This commit is contained in:
Casey Rodarmor 2022-01-02 16:51:22 -08:00 committed by GitHub
parent a3b25c1a3a
commit 3372efefc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 11 deletions

View File

@ -28,14 +28,18 @@ impl<'src> Line<'src> {
pub(crate) fn is_quiet(&self) -> bool { pub(crate) fn is_quiet(&self) -> bool {
match self.fragments.first() { match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('@'), Some(Fragment::Text { token }) => {
token.lexeme().starts_with('@') || token.lexeme().starts_with("-@")
}
_ => false, _ => false,
} }
} }
pub(crate) fn is_infallable(&self) -> bool { pub(crate) fn is_infallible(&self) -> bool {
match self.fragments.first() { match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('-'), Some(Fragment::Text { token }) => {
token.lexeme().starts_with('-') || token.lexeme().starts_with("@-")
}
_ => false, _ => false,
} }
} }

View File

@ -213,7 +213,7 @@ impl<'src, D> Recipe<'src, D> {
let mut evaluated = String::new(); let mut evaluated = String::new();
let mut continued = false; let mut continued = false;
let quiet_command = lines.peek().map_or(false, |line| line.is_quiet()); let quiet_command = lines.peek().map_or(false, |line| line.is_quiet());
let infallable_command = lines.peek().map_or(false, |line| line.is_infallable()); let infallible_command = lines.peek().map_or(false, |line| line.is_infallible());
loop { loop {
if lines.peek().is_none() { if lines.peek().is_none() {
break; break;
@ -229,7 +229,12 @@ impl<'src, D> Recipe<'src, D> {
} }
} }
let mut command = evaluated.as_str(); let mut command = evaluated.as_str();
if quiet_command || infallable_command {
if quiet_command {
command = &command[1..];
}
if infallible_command {
command = &command[1..]; command = &command[1..];
} }
@ -274,7 +279,7 @@ impl<'src, D> Recipe<'src, D> {
match InterruptHandler::guard(|| cmd.status()) { match InterruptHandler::guard(|| cmd.status()) {
Ok(exit_status) => { Ok(exit_status) => {
if let Some(code) = exit_status.code() { if let Some(code) = exit_status.code() {
if code != 0 && !infallable_command { if code != 0 && !infallible_command {
return Err(Error::Code { return Err(Error::Code {
recipe: self.name(), recipe: self.name(),
line_number: Some(line_number), line_number: Some(line_number),

View File

@ -24,6 +24,7 @@ mod init;
mod interrupts; mod interrupts;
mod invocation_directory; mod invocation_directory;
mod json; mod json;
mod line_prefixes;
mod misc; mod misc;
mod positional_arguments; mod positional_arguments;
mod quiet; mod quiet;

25
tests/line_prefixes.rs Normal file
View File

@ -0,0 +1,25 @@
use crate::common::*;
#[test]
fn infallible_after_quiet() {
Test::new()
.justfile(
"
foo:
@-exit 1
",
)
.run();
}
#[test]
fn quiet_after_infallible() {
Test::new()
.justfile(
"
foo:
-@exit 1
",
)
.run();
}

View File

@ -1035,9 +1035,9 @@ foo:
} }
test! { test! {
name: infallable_command, name: infallible_command,
justfile: r#" justfile: r#"
infallable: infallible:
-exit 101 -exit 101
"#, "#,
stderr: "exit 101\n", stderr: "exit 101\n",
@ -1045,15 +1045,15 @@ infallable:
} }
test! { test! {
name: infallable_with_failing, name: infallible_with_failing,
justfile: r#" justfile: r#"
infallable: infallible:
-exit 101 -exit 101
exit 202 exit 202
"#, "#,
stderr: r#"exit 101 stderr: r#"exit 101
exit 202 exit 202
error: Recipe `infallable` failed on line 3 with exit code 202 error: Recipe `infallible` failed on line 3 with exit code 202
"#, "#,
status: 202, status: 202,
} }