Skip to content

Commit

Permalink
Added a repository field to the Metadata struct (fixes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Sep 26, 2021
1 parent ffe447a commit 8fbfe99
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub struct Metadata {
pub authors: Cow<'static, str>,
/// The URL of the crate's website
pub homepage: Cow<'static, str>,
/// The URL of the crate's repository
pub repository: Cow<'static, str>,
}

/// `human-panic` initialisation macro
Expand Down Expand Up @@ -119,6 +121,7 @@ macro_rules! setup_panic {
name: env!("CARGO_PKG_NAME").into(),
authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(),
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
repository: env!("CARGO_PKG_REPOSITORY").into(),
};

panic::set_hook(Box::new(move |info: &PanicInfo| {
Expand All @@ -137,8 +140,8 @@ pub fn print_msg<P: AsRef<Path>>(
file_path: Option<P>,
meta: &Metadata,
) -> IoResult<()> {
let (_version, name, authors, homepage) =
(&meta.version, &meta.name, &meta.authors, &meta.homepage);
let (_version, name, authors, homepage, repository) =
(&meta.version, &meta.name, &meta.authors, &meta.homepage, &meta.repository);

let stderr = BufferWriter::stderr(ColorChoice::Auto);
let mut buffer = stderr.buffer();
Expand Down Expand Up @@ -166,6 +169,9 @@ pub fn print_msg<P: AsRef<Path>>(
if !homepage.is_empty() {
writeln!(&mut buffer, "- Homepage: {}", homepage)?;
}
if !repository.is_empty() && repository != homepage {
writeln!(&mut buffer, "- Repository: {}", repository)?;
}
if !authors.is_empty() {
writeln!(&mut buffer, "- Authors: {}", authors)?;
}
Expand Down

0 comments on commit 8fbfe99

Please sign in to comment.