From d4309521f10b6f0090ef2548fb8f241949074e1f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 4 May 2026 14:48:25 +0900 Subject: feat(show): expand license output with name, OSI flag, and URL Mirror Composer's Command\ShowCommand::printLicenses(): emit one line per license identifier, expanded to " () [(OSI approved)] " when the id is in the SPDX database, or just the id otherwise. The URL is built by mozart-spdx-licenses' new LicenseInfo::url() so the construction lives in the SPDX crate, like Composer's SpdxLicenses::getLicenseByIdentifier(). --- crates/mozart-spdx-licenses/src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/mozart-spdx-licenses/src/lib.rs') diff --git a/crates/mozart-spdx-licenses/src/lib.rs b/crates/mozart-spdx-licenses/src/lib.rs index a551988..0747703 100644 --- a/crates/mozart-spdx-licenses/src/lib.rs +++ b/crates/mozart-spdx-licenses/src/lib.rs @@ -12,6 +12,18 @@ pub struct LicenseInfo { pub deprecated: bool, } +impl LicenseInfo { + /// Canonical SPDX URL for this license. Mirrors Composer's + /// `SpdxLicenses::getLicenseByIdentifier()` which constructs the URL from + /// the identifier rather than storing it in the data file. + pub fn url(&self) -> String { + format!( + "https://spdx.org/licenses/{}.html#licenseText", + self.identifier + ) + } +} + /// Information about an SPDX license exception. #[derive(Debug, Clone)] pub struct ExceptionInfo { @@ -450,6 +462,21 @@ mod tests { assert!(db.get_license_by_identifier("nonexistent").is_none()); } + #[test] + fn license_url_uses_canonical_id() { + let db = spdx(); + let mit = db.get_license_by_identifier("MIT").unwrap(); + assert_eq!(mit.url(), "https://spdx.org/licenses/MIT.html#licenseText"); + + // Lookup is case-insensitive, but the URL uses the canonical casing + // from the database, mirroring Composer's `getLicenseByIdentifier`. + let mit_lower = db.get_license_by_identifier("mit").unwrap(); + assert_eq!( + mit_lower.url(), + "https://spdx.org/licenses/MIT.html#licenseText" + ); + } + #[test] fn exception_lookup() { let db = spdx(); -- cgit v1.3.1