mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
feat: Show output of subprocess as error prompt ✨
This commit is contained in:
parent
d5fb99a8d7
commit
b6a4a8c8a0
1 changed files with 27 additions and 16 deletions
43
src/app.rs
43
src/app.rs
|
@ -1682,22 +1682,30 @@ impl TaskwarriorTui {
|
|||
|
||||
let r = match shlex::split(shell) {
|
||||
Some(cmd) => {
|
||||
// first argument must be a binary
|
||||
let mut command = Command::new(&cmd[0]);
|
||||
// remaining arguments are args
|
||||
for (i, s) in cmd.iter().enumerate() {
|
||||
if i == 0 {
|
||||
continue;
|
||||
if cmd.is_empty() {
|
||||
Err(format!("Shell command empty: {}", shell))
|
||||
} else {
|
||||
// first argument must be a binary
|
||||
let mut command = Command::new(&cmd[0]);
|
||||
// remaining arguments are args
|
||||
for (i, s) in cmd.iter().enumerate() {
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
command.arg(&s);
|
||||
}
|
||||
let output = command.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let output = String::from_utf8_lossy(&o.stdout);
|
||||
if !output.is_empty() {
|
||||
Err(format!("Shell command `{}` ran successfully but printed the following output:\n\n{}\n\nSuppress output of shell commands to prevent the error prompt from showing up.", shell, output))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Err(_) => Err(format!("Shell command `{}` exited with non-zero output", shell)),
|
||||
}
|
||||
command.arg(&s);
|
||||
}
|
||||
let output = command.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
debug!("output: {}", String::from_utf8_lossy(&o.stdout));
|
||||
Ok(())
|
||||
},
|
||||
Err(_) => Err(format!("Shell command `{}` exited with non-zero output", shell)),
|
||||
}
|
||||
}
|
||||
None => Err(format!("Cannot run subprocess. Unable to shlex split `{}`", shell)),
|
||||
|
@ -1802,7 +1810,10 @@ impl TaskwarriorTui {
|
|||
match output {
|
||||
Ok(o) => {
|
||||
if o.status.success() {
|
||||
debug!("output: {}", String::from_utf8_lossy(&o.stdout));
|
||||
let output = String::from_utf8_lossy(&o.stdout);
|
||||
if !output.is_empty() {
|
||||
self.error = Some(format!("`{:?}`:\n{}", &command, output));
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue