From 2d6b76759493bf6d4636146cccf8a5b54606d5ca Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 17 Apr 2024 19:07:27 +0800 Subject: [PATCH] feat: Add support links Signed-off-by: tison --- src/lib.rs | 24 ++++++++++++++++++++++-- tests/custom-panic/src/main.rs | 3 ++- tests/custom-panic/tests/integration.rs | 8 ++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6195518..881049c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,7 @@ pub struct Metadata { version: Cow<'static, str>, authors: Option>, homepage: Option>, + support: Option>, } impl Metadata { @@ -70,6 +71,7 @@ impl Metadata { version: version.into(), authors: None, homepage: None, + support: None, } } @@ -90,6 +92,15 @@ impl Metadata { } self } + + /// The support information + pub fn support(mut self, value: impl Into>) -> Self { + let value = value.into(); + if !value.is_empty() { + self.support = value.into(); + } + self + } } /// Initialize [`Metadata`] @@ -121,6 +132,7 @@ macro_rules! metadata { /// setup_panic!(Metadata::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")) /// .authors("My Company Support ") /// .homepage("support.mycompany.com") +/// .support("- Open a support request by email to support@mycompany.com") /// ); /// ``` #[macro_export] @@ -206,8 +218,13 @@ fn write_msg>( file_path: Option

, meta: &Metadata, ) -> IoResult<()> { - let (_version, name, authors, homepage) = - (&meta.version, &meta.name, &meta.authors, &meta.homepage); + let Metadata { + name, + authors, + homepage, + support, + .. + } = meta; writeln!(buffer, "Well, this is embarrassing.\n")?; writeln!( @@ -233,6 +250,9 @@ fn write_msg>( if let Some(authors) = authors { writeln!(buffer, "- Authors: {authors}")?; } + if let Some(support) = support { + writeln!(buffer, "\nTo submit the crash report:\n\n{support}")?; + } writeln!( buffer, "\nWe take privacy seriously, and do not perform any \ diff --git a/tests/custom-panic/src/main.rs b/tests/custom-panic/src/main.rs index b06bcc3..ff71b86 100644 --- a/tests/custom-panic/src/main.rs +++ b/tests/custom-panic/src/main.rs @@ -4,7 +4,8 @@ use human_panic::setup_panic; fn main() { setup_panic!(metadata!() .authors("My Company Support