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 {
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,
}
}
pub(crate) fn is_infallable(&self) -> bool {
pub(crate) fn is_infallible(&self) -> bool {
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,
}
}

View File

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

View File

@ -24,6 +24,7 @@ mod init;
mod interrupts;
mod invocation_directory;
mod json;
mod line_prefixes;
mod misc;
mod positional_arguments;
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! {
name: infallable_command,
name: infallible_command,
justfile: r#"
infallable:
infallible:
-exit 101
"#,
stderr: "exit 101\n",
@ -1045,15 +1045,15 @@ infallable:
}
test! {
name: infallable_with_failing,
name: infallible_with_failing,
justfile: r#"
infallable:
infallible:
-exit 101
exit 202
"#,
stderr: r#"exit 101
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,
}