Add .exe to powershell scripts (#826)

This commit is contained in:
sigoden 2021-05-12 03:21:49 +08:00 committed by GitHub
parent d8c00ac2e4
commit cba52c9d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 14 deletions

View File

@ -107,6 +107,18 @@ impl<'src, D> Recipe<'src, D> {
return Ok(());
}
let shebang_line = evaluated_lines
.first()
.ok_or_else(|| RuntimeError::Internal {
message: "evaluated_lines was empty".to_owned(),
})?;
let Shebang {
interpreter,
argument,
} = Shebang::new(shebang_line).ok_or_else(|| RuntimeError::Internal {
message: format!("bad shebang line: {}", shebang_line),
})?;
let tmp = tempfile::Builder::new()
.prefix("just")
.tempdir()
@ -115,7 +127,13 @@ impl<'src, D> Recipe<'src, D> {
io_error: error,
})?;
let mut path = tmp.path().to_path_buf();
path.push(self.name());
let suffix = if interpreter.ends_with("powershell") || interpreter.ends_with("powershell.exe")
{
".ps1"
} else {
""
};
path.push(format!("{}{}", self.name(), suffix));
{
let mut f = fs::File::create(&path).map_err(|error| RuntimeError::TmpdirIoError {
recipe: self.name(),
@ -152,19 +170,6 @@ impl<'src, D> Recipe<'src, D> {
io_error: error,
})?;
let shebang_line = evaluated_lines
.first()
.ok_or_else(|| RuntimeError::Internal {
message: "evaluated_lines was empty".to_owned(),
})?;
let Shebang {
interpreter,
argument,
} = Shebang::new(shebang_line).ok_or_else(|| RuntimeError::Internal {
message: format!("bad shebang line: {}", shebang_line),
})?;
// create a command to run the script
let mut command = Platform::make_shebang_command(
&path,

View File

@ -22,6 +22,7 @@ mod positional_arguments;
mod quiet;
mod readme;
mod search;
mod shebang;
mod shell;
mod string;
mod working_directory;

21
tests/shebang.rs Normal file
View File

@ -0,0 +1,21 @@
#[cfg(windows)]
test! {
name: powershell,
justfile: r#"
default:
#!powershell
Write-Host Hello-World
"#,
stdout: "Hello-World\n",
}
#[cfg(windows)]
test! {
name: powershell_exe,
justfile: r#"
default:
#!powershell.exe
Write-Host Hello-World
"#,
stdout: "Hello-World\n",
}