From 7be66f890f4605272191025fd3d20dc698c6f1c4 Mon Sep 17 00:00:00 2001 From: Lynx Zhou Date: Sun, 16 May 2021 13:33:41 +0800 Subject: [PATCH] Add shebang support for 'cmd.exe' (#828) --- src/recipe.rs | 11 ++++++++--- tests/shebang.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/recipe.rs b/src/recipe.rs index beadec8..288b38c 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -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 diff --git a/tests/shebang.rs b/tests/shebang.rs index a3fb526..18091bb 100644 --- a/tests/shebang.rs +++ b/tests/shebang.rs @@ -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", +}