From c9ce4601b9b362ffe6d2270fcfb0fecf62e15965 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 20 Apr 2017 23:06:03 -0700 Subject: [PATCH] Add --shell option to specify the shell to use (#175) Mostly for debugging purposes, so I can make sure behavior is consistent across different shells. Although I suppose this might also be of use if you've got a mega weird `sh` that you'd like to avoid. Defaults to `sh` so current behavior is preserved. --- src/app.rs | 8 +++++++- src/integration.rs | 2 +- src/lib.rs | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index adebb66..03ba4e3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,7 +6,7 @@ extern crate ansi_term; use std::{io, fs, env, process, convert, ffi}; use std::collections::BTreeMap; use self::clap::{App, Arg, ArgGroup, AppSettings}; -use super::{Slurp, RunError, RunOptions, compile}; +use super::{Slurp, RunError, RunOptions, compile, DEFAULT_SHELL}; macro_rules! warn { ($($arg:tt)*) => {{ @@ -135,6 +135,11 @@ pub fn app() { .value_names(&["variable", "value"]) .multiple(true) .help("Sets to ")) + .arg(Arg::with_name("shell") + .long("shell") + .takes_value(true) + .default_value(DEFAULT_SHELL) + .help("Invoke to run recipes")) .arg(Arg::with_name("show") .short("s") .long("show") @@ -333,6 +338,7 @@ pub fn app() { evaluate: matches.is_present("evaluate"), overrides: overrides, quiet: matches.is_present("quiet"), + shell: matches.value_of("shell"), use_color: use_color, verbose: matches.is_present("verbose"), }; diff --git a/src/integration.rs b/src/integration.rs index fc79fd1..9840c1e 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -938,7 +938,7 @@ fn quiet_flag_or_dry_run_flag() { "error: The argument '--dry-run' cannot be used with '--quiet' USAGE: - just --color --quiet + just --color --quiet --shell For more information try --help\n", ); diff --git a/src/lib.rs b/src/lib.rs index 875d717..a9da94b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,8 @@ macro_rules! die { }}; } +const DEFAULT_SHELL: &'static str = "sh"; + trait Slurp { fn slurp(&mut self) -> Result; } @@ -235,7 +237,7 @@ fn run_backtick<'a>( exports: &Set<&'a str>, quiet: bool, ) -> Result> { - let mut cmd = process::Command::new("sh"); + let mut cmd = process::Command::new(DEFAULT_SHELL); export_env(&mut cmd, scope, exports)?; @@ -440,7 +442,7 @@ impl<'a> Recipe<'a> { continue; } - let mut cmd = process::Command::new("sh"); + let mut cmd = process::Command::new(options.shell.unwrap_or(DEFAULT_SHELL)); cmd.arg("-cu").arg(command); @@ -1155,6 +1157,7 @@ struct RunOptions<'a> { evaluate: bool, overrides: Map<&'a str, &'a str>, quiet: bool, + shell: Option<&'a str>, use_color: UseColor, verbose: bool, }