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
12 changes: 0 additions & 12 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ impl PlatformInterface for Platform {
Ok(cmd)
}

fn get_recipe_file_ext(command: &str) -> String {
return String::new();
}

fn set_execute_permission(path: &Path) -> Result<(), io::Error> {
use std::os::unix::fs::PermissionsExt;

Expand Down Expand Up @@ -85,14 +81,6 @@ impl PlatformInterface for Platform {
Ok(cmd)
}

fn get_recipe_file_ext(command: &str) -> String {
if command.ends_with("powershell.exe") {
format!("{}", ".ps1")
} else {
String::new()
}
}

fn set_execute_permission(_path: &Path) -> Result<(), io::Error> {
// it is not necessary to set an execute permission on a script on windows, so
// this is a nop
Expand Down
8 changes: 7 additions & 1 deletion src/platform_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ pub(crate) trait PlatformInterface {
) -> Result<Command, OutputError>;

/// Get generate file ext
fn get_recipe_file_ext(command: &str) -> String;
fn get_script_file_ext(command: &str) -> &str {
sigoden marked this conversation as resolved.
Show resolved Hide resolved
if command.ends_with("powershell") {
sigoden marked this conversation as resolved.
Show resolved Hide resolved
".ps1"
} else {
""
}
}

/// Set the execute permission on the file pointed to by `path`
fn set_execute_permission(path: &Path) -> Result<(), io::Error>;
Expand Down
4 changes: 2 additions & 2 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl<'src, D> Recipe<'src, D> {
io_error: error,
})?;
let mut path = tmp.path().to_path_buf();
let ext = Platform::get_recipe_file_ext(interpreter);
path.push(format!("{}{}", self.name(), ext));
let ext_name = Platform::get_script_file_ext(interpreter);
sigoden marked this conversation as resolved.
Show resolved Hide resolved
path.push(format!("{}{}", self.name(), ext_name));
{
let mut f = fs::File::create(&path).map_err(|error| RuntimeError::TmpdirIoError {
recipe: self.name(),
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;
31 changes: 31 additions & 0 deletions tests/shebang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::{process::Command, str};

use executable_path::executable_path;

use test_utilities::{assert_stdout, tmptree};

const JUSTFILE_POWERSHELL: &str = r#"
set shell := ["powershell.exe", "-c"]

default:
#!powershell
Write-Host Hello-World
"#;

/// Test powershell shebang
#[test]
#[cfg_attr(unix, ignore)]
fn powershell() {
let tmp = tmptree! {
justfile: JUSTFILE_POWERSHELL,
};

let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.output()
.unwrap();

let stdout = "Hello-World\n";

assert_stdout(&output, stdout);
}
sigoden marked this conversation as resolved.
Show resolved Hide resolved