Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix powershell shebang, closes #825 #826

Merged
merged 10 commits into from
May 11, 2021
33 changes: 19 additions & 14 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod positional_arguments;
mod quiet;
mod readme;
mod search;
mod shebang;
mod shell;
mod string;
mod working_directory;
21 changes: 21 additions & 0 deletions tests/shebang.rs
Original file line number Diff line number Diff line change
@@ -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",
}