diff options
Diffstat (limited to 'crates/shirabe/src/command/show_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/show_command.rs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index 7a2c452..e99005e 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -1870,12 +1870,20 @@ impl ShowCommand { let out = match license { None => license_id.clone(), Some(license) => { - // TODO(phase-b): SpdxLicenses returns PhpMixed; field access (osi/fullname/url) - // is placeholder until PHP array offsets are wired. - let _ = &license; - let fullname = String::new(); - let url = String::new(); - let is_osi = false; + // SpdxLicenses::getLicenseByIdentifier returns [0 => fullname, 1 => osiApproved, 2 => url]. + let list = license.as_list(); + let fullname = list + .and_then(|l| l.get(0)) + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); + let is_osi = + list.and_then(|l| l.get(1)).and_then(|v| v.as_bool()) == Some(true); + let url = list + .and_then(|l| l.get(2)) + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); if is_osi { format!("{} ({}) (OSI approved) {}", fullname, license_id, url) } else { @@ -2116,12 +2124,23 @@ impl ShowCommand { match license { None => PhpMixed::String(license_id), Some(l) => { - // TODO(phase-b): SpdxLicenses returns PhpMixed; field access placeholder. - let _ = &l; + // PHP shape: ['name' => $license[0], 'osi' => $licenseId, 'url' => $license[2]]. + // Note 'osi' is the license id string, not the OSI-approved flag. + let list = l.as_list(); + let name = list + .and_then(|x| x.get(0)) + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); + let url = list + .and_then(|x| x.get(2)) + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert("name".to_string(), PhpMixed::String(String::new())); + m.insert("name".to_string(), PhpMixed::String(name)); m.insert("osi".to_string(), PhpMixed::String(license_id)); - m.insert("url".to_string(), PhpMixed::String(String::new())); + m.insert("url".to_string(), PhpMixed::String(url)); PhpMixed::Array(m.into_iter().map(|(k, v)| (k, Box::new(v))).collect()) } } |
