-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: add LicenseName
field to the output
#43
Comments
Hey @mmaetzler, I will investigate what's possible next weekend. AFAIK we don't have this information present out of the box. |
Thanks for the reply! Yeah after posting the feature request I went through the contents of the The example package I'm using is grpc-swift which contains the It looks like a bigger task 😢 |
Hey, so I did some research... We don't have any license identifier locally as mentioned before (which makes sense because it's not a git feature rather than GitHub). They have an API for that, but the big advantage of this tool is that everything is coming from local data and does not need any network request. You are totally right, GitHub is using (and maintaining) the Ruby gem Licensee to detect license types in GitHub. It would be possible to build something similar in Swift, we just need a mapping (with some tolerance) of the license text to a snapshot of the SPDX License List. However, I think this should not be part of this package itself because it's a different use case. As you guessed it, it is definitely a bigger task! I don't have time right now and something like that should be done right. I can think of a simple String-contains workaround for your project for now, like the following: enum LicenseType {
case mit
case apachev2
case gplv2
case gplv3
var spdxIdentifier: String {
switch self {
case .mit: return "MIT"
case .apachev2: return "Apache-2.0"
case .gplv2: return "GPL-2.0"
case .gplv3: return "GPL-3.0"
}
}
var localizedName: String {
let format = NSLocalizedString("LICENSE_NAME", value: "%@ license", comment: "The license name displayed to the user (%@ is the license type, e.g. Apache-2.0)")
return .localizedStringWithFormat(format, spdxIdentifier)
}
init?(license: String) {
if license.contains("MIT License") {
self = .mit
} else if license.contains("Apache License") && license.contains("Version 2.0") {
self = .apachev2
} else if license.contains("GNU GENERAL PUBLIC LICENSE") && license.contains("Version 2") {
self = .gplv2
} else if license.contains("GNU GENERAL PUBLIC LICENSE") && license.contains("Version 3") {
self = .gplv3
} else {
return nil
}
}
}
extension Package {
var licenseType: LicenseType? {
guard let license else { return nil }
return LicenseType(license: license)
}
} |
Thanks for looking into this so thoroughly, I appreciate it. I think for now I plan to run |
No problem! That's also a good workaround 🙂 |
If anyone wants to use this nicely written extension by @FelixHerrmann just make sure to wrap the Once again, thanks for your effort and work @FelixHerrmann ! Really enjoy using this. |
Oh you are totally right @NikolaiMadlener, this was not really tested. I have updated it in case someone just copies it. Thanks for correcting this! |
I want to start with saying: I love this software! Thanks for creating it!
I was wondering if there is an easy way to add the license name as a field to the output? The output files right now have a
license
file with the raw text of the license, but I was wondering if you would be open to add thelicenseName
, in the form of an SPDX license identifier to the output as well?Background: In our software attributions list, we list all the included components, their name, version and license identifier. Then, when one clicks on a license, the full text appears, but we first want to start by showing just the license identifier.
In our use case we are using the json output of the package list.
The text was updated successfully, but these errors were encountered: