Skip to content

Commit

Permalink
Improve chooser invocation error message (#772)
Browse files Browse the repository at this point in the history
Since the chooser is invoked via the shell, print out the full shell
command line, instead of just the chooser.
  • Loading branch information
casey committed Mar 26, 2021
1 parent b66a979 commit 122c351
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ impl Config {
Err(error) => {
if self.verbosity.loud() {
eprintln!(
"Chooser `{}` invocation failed: {}",
"Chooser `{} {} {}` invocation failed: {}",
justfile.settings.shell_binary(self),
justfile.settings.shell_arguments(self).join(" "),
chooser.to_string_lossy(),
error
);
Expand Down
30 changes: 20 additions & 10 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ impl<'src> Settings<'src> {
}

pub(crate) fn shell_command(&self, config: &Config) -> Command {
if let (Some(shell), false) = (&self.shell, config.shell_present) {
let mut cmd = Command::new(shell.command.cooked.as_ref());
let mut cmd = Command::new(self.shell_binary(config));

for argument in &shell.arguments {
cmd.arg(argument.cooked.as_ref());
}
cmd.args(self.shell_arguments(config));

cmd
} else {
let mut cmd = Command::new(&config.shell);
cmd
}

cmd.args(&config.shell_args);
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
}
}

cmd
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()
}
}
}

0 comments on commit 122c351

Please sign in to comment.