2017-08-11 22:18:09 +00:00
|
|
|
"""
|
|
|
|
Template(; kwargs...) -> Template
|
|
|
|
|
|
|
|
Records common information used to generate a package.
|
|
|
|
|
|
|
|
# Keyword Arguments
|
2017-08-16 22:01:52 +00:00
|
|
|
* `user::AbstractString="")`: GitHub username. If left unset, it will try to take the
|
|
|
|
value of a supplied git config's "github.username" key, then the global git config's
|
|
|
|
value. If neither is set, an `ArgumentError` is thrown.
|
|
|
|
**This is case-sensitive for some plugins, so take care to enter it correctly.**
|
|
|
|
* `host::AbstractString="github.com"`: URL to the code hosting service where your package
|
|
|
|
will reside.
|
|
|
|
* `license::Union{AbstractString, Void}=nothing`: Name of the package license. If
|
2017-08-16 06:58:54 +00:00
|
|
|
no license is specified, no license is created. [`show_license`](@ref) can be used to
|
|
|
|
list all available licenses, or to print out a particular license's text.
|
2017-08-16 22:01:52 +00:00
|
|
|
* `authors::Union{AbstractString, Array}=""`: Names that appear on the license. Supply a
|
|
|
|
string for one author, and an array for multiple. Similarly to `user`, it will try to
|
|
|
|
take the value of a supplied git config's "user.name" key, then the global git config's
|
|
|
|
value, if it is left unset
|
2017-08-14 18:13:14 +00:00
|
|
|
* `years::Union{Int, AbstractString}=string(Dates.year(Dates.today()))`: Copyright years
|
|
|
|
on the license. Can be supplied by a number, or a string such as "2016 - 2017".
|
2017-08-15 23:46:36 +00:00
|
|
|
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
|
2017-08-11 22:18:09 +00:00
|
|
|
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
|
|
|
* `git_config::Dict{String, String}=Dict{String, String}()`: Git configuration options.
|
|
|
|
* `plugins::Vector{Plugin}`: A list of `Plugin`s that the package will include.
|
|
|
|
"""
|
2017-08-14 18:12:37 +00:00
|
|
|
@auto_hash_equals struct Template
|
2017-08-15 16:10:05 +00:00
|
|
|
user::AbstractString
|
|
|
|
host::AbstractString
|
2017-08-11 22:18:09 +00:00
|
|
|
license::Union{AbstractString, Void}
|
|
|
|
authors::Union{AbstractString, Array}
|
|
|
|
years::AbstractString
|
2017-08-15 23:46:36 +00:00
|
|
|
dir::AbstractString
|
|
|
|
temp_dir::AbstractString
|
2017-08-11 22:18:09 +00:00
|
|
|
julia_version::VersionNumber
|
2017-08-16 06:11:53 +00:00
|
|
|
git_config::Dict
|
2017-08-11 22:18:09 +00:00
|
|
|
plugins::Dict{DataType, Plugin}
|
|
|
|
|
2017-08-15 16:10:05 +00:00
|
|
|
function Template(;
|
2017-08-16 22:01:52 +00:00
|
|
|
user::AbstractString="",
|
2017-08-15 16:10:05 +00:00
|
|
|
host::AbstractString="https://github.com",
|
2017-08-11 22:18:09 +00:00
|
|
|
license::Union{AbstractString, Void}=nothing,
|
2017-08-16 22:01:52 +00:00
|
|
|
authors::Union{AbstractString, Array}="",
|
2017-08-11 22:18:09 +00:00
|
|
|
years::Union{Int, AbstractString}=string(Dates.year(Dates.today())),
|
2017-08-15 23:46:36 +00:00
|
|
|
dir::AbstractString=Pkg.dir(),
|
2017-08-11 22:18:09 +00:00
|
|
|
julia_version::VersionNumber=VERSION,
|
2017-08-16 06:11:53 +00:00
|
|
|
git_config::Dict=Dict(),
|
2017-08-11 22:18:09 +00:00
|
|
|
plugins::Vector{P}=Vector{Plugin}(),
|
2017-08-15 16:10:05 +00:00
|
|
|
) where P <: Plugin
|
2017-08-16 22:01:52 +00:00
|
|
|
# If no username was set, look for one in a supplied git config,
|
|
|
|
# and then in the global git config.
|
|
|
|
if isempty(user)
|
|
|
|
user = get(
|
|
|
|
git_config, "github.username",
|
|
|
|
LibGit2.getconfig("github.username", ""),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
if isempty(user)
|
2017-08-15 16:10:05 +00:00
|
|
|
throw(ArgumentError("No GitHub username found, set one with user=username"))
|
|
|
|
end
|
|
|
|
|
|
|
|
host = URI(startswith(host, "https://") ? host : "https://$host").host
|
|
|
|
|
|
|
|
if license != nothing && !isfile(joinpath(LICENSE_DIR, license))
|
|
|
|
throw(ArgumentError("License '$license' is not available"))
|
2017-08-11 22:18:09 +00:00
|
|
|
end
|
2017-08-14 20:58:01 +00:00
|
|
|
|
2017-08-16 22:01:52 +00:00
|
|
|
# If no author was set, look for one in the supplied git config,
|
|
|
|
# and then in the global git config.
|
|
|
|
if isempty(authors)
|
2017-08-14 20:58:01 +00:00
|
|
|
authors = get(git_config, "user.name", LibGit2.getconfig("user.name", ""))
|
|
|
|
elseif isa(authors, Array)
|
2017-08-11 22:18:09 +00:00
|
|
|
authors = join(authors, ", ")
|
|
|
|
end
|
|
|
|
|
2017-08-15 16:10:05 +00:00
|
|
|
years = string(years)
|
2017-08-14 19:15:53 +00:00
|
|
|
|
2017-08-15 23:46:36 +00:00
|
|
|
temp_dir = mktempdir()
|
|
|
|
|
2017-08-14 19:15:53 +00:00
|
|
|
plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins)
|
|
|
|
if (length(plugins) != length(plugin_dict))
|
|
|
|
warn("Plugin list contained duplicates, only the last of each type was kept")
|
|
|
|
end
|
2017-08-11 22:18:09 +00:00
|
|
|
|
|
|
|
new(
|
2017-08-15 23:46:36 +00:00
|
|
|
user, host, license, authors, years, dir, temp_dir,
|
2017-08-15 16:10:05 +00:00
|
|
|
julia_version, git_config, plugin_dict
|
2017-08-11 22:18:09 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|