2019-11-10 23:17:47 -08:00
|
|
|
use crate::common::*;
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
#[derive(Debug, PartialEq, Serialize)]
|
2019-11-10 23:17:47 -08:00
|
|
|
pub(crate) struct Settings<'src> {
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) dotenv_load: Option<bool>,
|
|
|
|
pub(crate) export: bool,
|
2021-04-24 18:29:58 -07:00
|
|
|
pub(crate) positional_arguments: bool,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) shell: Option<setting::Shell<'src>>,
|
2019-11-10 23:17:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Settings<'src> {
|
|
|
|
pub(crate) fn new() -> Settings<'src> {
|
2021-03-25 17:00:32 -07:00
|
|
|
Settings {
|
2021-09-16 06:44:40 -07:00
|
|
|
dotenv_load: None,
|
|
|
|
export: false,
|
2021-04-24 18:29:58 -07:00
|
|
|
positional_arguments: false,
|
2021-09-16 06:44:40 -07:00
|
|
|
shell: None,
|
2021-03-25 17:00:32 -07:00
|
|
|
}
|
2019-11-10 23:17:47 -08:00
|
|
|
}
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
pub(crate) fn shell_command(&self, config: &Config) -> Command {
|
2021-03-25 17:44:18 -07:00
|
|
|
let mut cmd = Command::new(self.shell_binary(config));
|
2019-11-10 23:17:47 -08:00
|
|
|
|
2021-03-25 17:44:18 -07:00
|
|
|
cmd.args(self.shell_arguments(config));
|
2019-11-10 23:17:47 -08:00
|
|
|
|
2021-03-25 17:44:18 -07:00
|
|
|
cmd
|
|
|
|
}
|
2019-11-10 23:17:47 -08:00
|
|
|
|
2021-03-25 17:44:18 -07:00
|
|
|
pub(crate) fn shell_binary<'a>(&'a self, config: &'a Config) -> &'a str {
|
|
|
|
if let (Some(shell), false) = (&self.shell, config.shell_present) {
|
|
|
|
shell.command.cooked.as_ref()
|
|
|
|
} else {
|
|
|
|
&config.shell
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 23:17:47 -08:00
|
|
|
|
2021-03-25 17:44:18 -07:00
|
|
|
pub(crate) fn shell_arguments<'a>(&'a self, config: &'a Config) -> Vec<&'a str> {
|
|
|
|
if let (Some(shell), false) = (&self.shell, config.shell_present) {
|
|
|
|
shell
|
|
|
|
.arguments
|
|
|
|
.iter()
|
|
|
|
.map(|argument| argument.cooked.as_ref())
|
|
|
|
.collect()
|
|
|
|
} else {
|
|
|
|
config.shell_args.iter().map(String::as_ref).collect()
|
2019-11-10 23:17:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|