elide header from command output when no logs captured
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b2d8da489c
commit
2cf472a69b
1 changed files with 15 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
|
fmt::Write,
|
||||||
panic::AssertUnwindSafe,
|
panic::AssertUnwindSafe,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
|
@ -109,10 +110,21 @@ async fn process(context: &Command<'_>, command: AdminCommand, args: &[String])
|
||||||
"command processed"
|
"command processed"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
// Prepend the logs only if any were captured
|
||||||
let logs = logs.lock().expect("locked");
|
let logs = logs.lock().expect("locked");
|
||||||
let output = match result {
|
if logs.lines().count() > 2 {
|
||||||
Err(error) => format!("{logs}\nEncountered an error while handling the command:\n```\n{error:#?}\n```"),
|
writeln!(&mut output, "{logs}").expect("failed to format logs to command output");
|
||||||
Ok(reply) => format!("{logs}\n{}", reply.body()), //TODO: content is recreated to add logs
|
}
|
||||||
|
drop(logs);
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(content) => {
|
||||||
|
write!(&mut output, "{}", content.body()).expect("failed to format command result to output");
|
||||||
|
},
|
||||||
|
Err(error) => write!(&mut output, "Command failed with error:\n```\n{error:#?}\n```")
|
||||||
|
.expect("failed to format error to command output"),
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(RoomMessageEventContent::notice_markdown(output))
|
Some(RoomMessageEventContent::notice_markdown(output))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue