Add shebang support for 'cmd.exe' (#828)

This commit is contained in:
Lynx Zhou 2021-05-16 13:33:41 +08:00 committed by GitHub
parent b26cb891b9
commit 7be66f890f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -127,8 +127,9 @@ impl<'src, D> Recipe<'src, D> {
io_error: error,
})?;
let mut path = tmp.path().to_path_buf();
let suffix = if interpreter.ends_with("powershell") || interpreter.ends_with("powershell.exe")
{
let suffix = if interpreter.ends_with("cmd") || interpreter.ends_with("cmd.exe") {
".bat"
} else if interpreter.ends_with("powershell") || interpreter.ends_with("powershell.exe") {
".ps1"
} else {
""
@ -141,7 +142,11 @@ impl<'src, D> Recipe<'src, D> {
})?;
let mut text = String::new();
// add the shebang
text += &evaluated_lines[0];
if interpreter.ends_with("cmd") || interpreter.ends_with("cmd.exe") {
text += "\n";
} else {
text += &evaluated_lines[0];
}
text += "\n";
// add blank lines so that lines in the generated script have the same line
// number as the corresponding lines in the justfile

View File

@ -19,3 +19,25 @@ default:
"#,
stdout: "Hello-World\n",
}
#[cfg(windows)]
test! {
name: cmd,
justfile: r#"
default:
#!cmd /c
@echo Hello-World
"#,
stdout: "Hello-World\r\n",
}
#[cfg(windows)]
test! {
name: cmd_exe,
justfile: r#"
default:
#!cmd.exe /c
@echo Hello-World
"#,
stdout: "Hello-World\r\n",
}