Improve chooser invocation error message (#772)

Since the chooser is invoked via the shell, print out the full shell
command line, instead of just the chooser.
This commit is contained in:
Casey Rodarmor 2021-03-25 17:44:18 -07:00 committed by GitHub
parent b66a979c08
commit 122c351eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View File

@ -571,7 +571,9 @@ impl Config {
Err(error) => { Err(error) => {
if self.verbosity.loud() { if self.verbosity.loud() {
eprintln!( eprintln!(
"Chooser `{}` invocation failed: {}", "Chooser `{} {} {}` invocation failed: {}",
justfile.settings.shell_binary(self),
justfile.settings.shell_arguments(self).join(" "),
chooser.to_string_lossy(), chooser.to_string_lossy(),
error error
); );

View File

@ -15,20 +15,30 @@ impl<'src> Settings<'src> {
} }
pub(crate) fn shell_command(&self, config: &Config) -> Command { pub(crate) fn shell_command(&self, config: &Config) -> Command {
let mut cmd = Command::new(self.shell_binary(config));
cmd.args(self.shell_arguments(config));
cmd
}
pub(crate) fn shell_binary<'a>(&'a self, config: &'a Config) -> &'a str {
if let (Some(shell), false) = (&self.shell, config.shell_present) { if let (Some(shell), false) = (&self.shell, config.shell_present) {
let mut cmd = Command::new(shell.command.cooked.as_ref()); shell.command.cooked.as_ref()
for argument in &shell.arguments {
cmd.arg(argument.cooked.as_ref());
}
cmd
} else { } else {
let mut cmd = Command::new(&config.shell); &config.shell
}
}
cmd.args(&config.shell_args); pub(crate) fn shell_arguments<'a>(&'a self, config: &'a Config) -> Vec<&'a str> {
if let (Some(shell), false) = (&self.shell, config.shell_present) {
cmd shell
.arguments
.iter()
.map(|argument| argument.cooked.as_ref())
.collect()
} else {
config.shell_args.iter().map(String::as_ref).collect()
} }
} }
} }