Skip to content

Commit

Permalink
Add shebang support for 'cmd.exe' (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
pansila authored May 16, 2021
1 parent b26cb89 commit 7be66f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
""
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/shebang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

0 comments on commit 7be66f8

Please sign in to comment.