Check and warn for unused keywords, update some metadata
This commit is contained in:
parent
ad8e78d87e
commit
266a22d5c2
2
LICENSE
2
LICENSE
@ -1,3 +1,5 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2019 Chris de Graaf, Invenia Technical Computing Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -1,6 +1,6 @@
|
||||
name = "PkgTemplates"
|
||||
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
|
||||
authors = ["Chris de Graaf <chrisadegraaf@gmail.com>"]
|
||||
authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"]
|
||||
version = "0.7.0"
|
||||
|
||||
[deps]
|
||||
|
@ -57,18 +57,20 @@ Template(; kwargs...) = Template(Val(false); kwargs...)
|
||||
|
||||
# Non-interactive constructor.
|
||||
function Template(::Val{false}; kwargs...)
|
||||
user = getkw(kwargs, :user)
|
||||
dir = abspath(expanduser(getkw(kwargs, :dir)))
|
||||
host = replace(getkw(kwargs, :host), r".*://" => "")
|
||||
julia = getkw(kwargs, :julia)
|
||||
kwargs = Dict(kwargs)
|
||||
|
||||
authors = getkw(kwargs, :authors)
|
||||
user = getkw!(kwargs, :user)
|
||||
dir = abspath(expanduser(getkw!(kwargs, :dir)))
|
||||
host = replace(getkw!(kwargs, :host), r".*://" => "")
|
||||
julia = getkw!(kwargs, :julia)
|
||||
|
||||
authors = getkw!(kwargs, :authors)
|
||||
authors isa Vector || (authors = map(strip, split(authors, ",")))
|
||||
|
||||
# User-supplied plugins come first, so that deduping the list will remove the defaults.
|
||||
plugins = Plugin[]
|
||||
append!(plugins, getkw(kwargs, :plugins))
|
||||
disabled = getkw(kwargs, :disable_defaults)
|
||||
append!(plugins, getkw!(kwargs, :plugins))
|
||||
disabled = getkw!(kwargs, :disable_defaults)
|
||||
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
|
||||
plugins = sort(unique(typeof, plugins); by=string)
|
||||
|
||||
@ -82,6 +84,8 @@ function Template(::Val{false}; kwargs...)
|
||||
end
|
||||
end
|
||||
|
||||
isempty(kwargs) || @warn "Unrecognized keywords were supplied" kwargs
|
||||
|
||||
t = Template(authors, dir, host, julia, plugins, user)
|
||||
foreach(p -> validate(p, t), t.plugins)
|
||||
return t
|
||||
@ -120,11 +124,11 @@ hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T)
|
||||
# Get a plugin by type.
|
||||
function getplugin(t::Template, ::Type{T}) where T <: Plugin
|
||||
i = findfirst(p -> p isa T, t.plugins)
|
||||
i === nothing ? nothing : t.plugins[i]
|
||||
return i === nothing ? nothing : t.plugins[i]
|
||||
end
|
||||
|
||||
# Get a keyword, or compute some default value.
|
||||
getkw(kwargs, k) = get(() -> defaultkw(Template, k), kwargs, k)
|
||||
# Get a keyword or a default value.
|
||||
getkw!(kwargs, k) = pop!(kwargs, k, defaultkw(Template, k))
|
||||
|
||||
# Default Template keyword values.
|
||||
defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s))
|
||||
|
@ -3,7 +3,7 @@ using Base.Filesystem: contractuser, path_separator
|
||||
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo
|
||||
using Pkg: Pkg
|
||||
using Random: Random
|
||||
using Test: @test, @testset, @test_throws
|
||||
using Test: @test, @testset, @test_logs, @test_throws
|
||||
|
||||
using ReferenceTests: @test_reference
|
||||
using SimpleMock: mock
|
||||
|
@ -43,6 +43,11 @@
|
||||
# Disabling a default plugin.
|
||||
test_plugins([], setdiff(defaults, [default_g]), [Git])
|
||||
end
|
||||
|
||||
@testset "Unsupported keywords warning" begin
|
||||
@test_logs tpl()
|
||||
@test_logs (:warn, "Unrecognized keywords were supplied") tpl(; x=1, y=2)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "hasplugin" begin
|
||||
|
Loading…
Reference in New Issue
Block a user