PkgTemplates.jl/src/licenses.jl

43 lines
1.4 KiB
Julia
Raw Normal View History

2017-08-23 17:50:52 +00:00
const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "licenses"))
const LICENSES = Dict(
"MIT" => "MIT \"Expat\" License",
"BSD" => "Simplified \"2-clause\" BSD License",
"ASL" => "Apache License, Version 2.0",
"MPL" => "Mozilla Public License, Version 2.0",
"GPL-2.0+" => "GNU Public License, Version 2.0+",
"GPL-3.0+" => "GNU Public License, Version 3.0+",
"LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+",
"LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+"
)
"""
2017-08-25 06:25:26 +00:00
available_licenses([io::IO]) -> Void
2017-08-23 17:50:52 +00:00
Print the names of all available licenses.
"""
available_licenses(io::IO) = println(io, join(["$k: $v" for (k, v) in LICENSES], "\n"))
available_licenses() = available_licenses(STDOUT)
"""
show_license([io::IO], license::AbstractString) -> Void
Print the text of `license`.
"""
show_license(io::IO, license::AbstractString) = println(io, read_license(license))
show_license(license::AbstractString) = show_license(STDOUT, license)
"""
2017-08-25 06:25:26 +00:00
read_license(license::AbstractString) -> String
2017-08-23 17:50:52 +00:00
2017-08-25 06:25:26 +00:00
Returns the contents of `license`. Errors if it is not found. Use
[`available_licenses`](@ref) to view available licenses.
2017-08-23 17:50:52 +00:00
"""
function read_license(license::AbstractString)
path = joinpath(LICENSE_DIR, license)
if isfile(path)
return string(readchomp(path))
else
throw(ArgumentError("License '$license' is not available"))
end
end