diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-04 14:48:25 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-04 15:44:11 +0900 |
| commit | d4309521f10b6f0090ef2548fb8f241949074e1f (patch) | |
| tree | 3c7fa9049b34e73e9a73e21bf19f8a3674c54c57 /crates/mozart-spdx-licenses/src | |
| parent | a24d6e2f148417b32188cd1e643439a2858f4eac (diff) | |
| download | php-mozart-d4309521f10b6f0090ef2548fb8f241949074e1f.tar.gz php-mozart-d4309521f10b6f0090ef2548fb8f241949074e1f.tar.zst php-mozart-d4309521f10b6f0090ef2548fb8f241949074e1f.zip | |
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 "<full name> (<id>) [(OSI
approved)] <url>" 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().
Diffstat (limited to 'crates/mozart-spdx-licenses/src')
| -rw-r--r-- | crates/mozart-spdx-licenses/src/lib.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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 { @@ -451,6 +463,21 @@ mod tests { } #[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(); let exc = db |
