e80bf34d9a
Add a `set SETTING := VALUE` construct. This construct is intended to be extended as needed with new settings, but for now we're starting with `set shell := [COMMAND, ARG1, ...]`, which allows setting the shell to use for recipe and backtick execution in a justfile. One of the primary reasons for adding this feature is to have a better story on windows, where users are forced to scrounge up an `sh` binary if they want to use `just`. This should allow them to use cmd.exe or powershell in their justfiles, making just optionally dependency-free.
31 lines
630 B
Rust
31 lines
630 B
Rust
use crate::common::*;
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub(crate) struct Settings<'src> {
|
|
pub(crate) shell: Option<setting::Shell<'src>>,
|
|
}
|
|
|
|
impl<'src> Settings<'src> {
|
|
pub(crate) fn new() -> Settings<'src> {
|
|
Settings { shell: None }
|
|
}
|
|
|
|
pub(crate) fn shell_command(&self, default_shell: &str) -> Command {
|
|
if let Some(shell) = &self.shell {
|
|
let mut cmd = Command::new(shell.command.cooked.as_ref());
|
|
|
|
for argument in &shell.arguments {
|
|
cmd.arg(argument.cooked.as_ref());
|
|
}
|
|
|
|
cmd
|
|
} else {
|
|
let mut cmd = Command::new(default_shell);
|
|
|
|
cmd.arg("-cu");
|
|
|
|
cmd
|
|
}
|
|
}
|
|
}
|