Check and warn for unused keywords, update some metadata

This commit is contained in:
Chris de Graaf 2019-10-06 16:12:20 +07:00
parent ad8e78d87e
commit 266a22d5c2
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
5 changed files with 23 additions and 12 deletions

View File

@ -1,3 +1,5 @@
MIT License
Copyright (c) 2017-2019 Chris de Graaf, Invenia Technical Computing Corporation Copyright (c) 2017-2019 Chris de Graaf, Invenia Technical Computing Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy

View File

@ -1,6 +1,6 @@
name = "PkgTemplates" name = "PkgTemplates"
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" 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" version = "0.7.0"
[deps] [deps]

View File

@ -57,18 +57,20 @@ Template(; kwargs...) = Template(Val(false); kwargs...)
# Non-interactive constructor. # Non-interactive constructor.
function Template(::Val{false}; kwargs...) function Template(::Val{false}; kwargs...)
user = getkw(kwargs, :user) kwargs = Dict(kwargs)
dir = abspath(expanduser(getkw(kwargs, :dir)))
host = replace(getkw(kwargs, :host), r".*://" => "")
julia = getkw(kwargs, :julia)
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, ","))) authors isa Vector || (authors = map(strip, split(authors, ",")))
# User-supplied plugins come first, so that deduping the list will remove the defaults. # User-supplied plugins come first, so that deduping the list will remove the defaults.
plugins = Plugin[] plugins = Plugin[]
append!(plugins, getkw(kwargs, :plugins)) append!(plugins, getkw!(kwargs, :plugins))
disabled = getkw(kwargs, :disable_defaults) disabled = getkw!(kwargs, :disable_defaults)
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
plugins = sort(unique(typeof, plugins); by=string) plugins = sort(unique(typeof, plugins); by=string)
@ -82,6 +84,8 @@ function Template(::Val{false}; kwargs...)
end end
end end
isempty(kwargs) || @warn "Unrecognized keywords were supplied" kwargs
t = Template(authors, dir, host, julia, plugins, user) t = Template(authors, dir, host, julia, plugins, user)
foreach(p -> validate(p, t), t.plugins) foreach(p -> validate(p, t), t.plugins)
return t 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. # Get a plugin by type.
function getplugin(t::Template, ::Type{T}) where T <: Plugin function getplugin(t::Template, ::Type{T}) where T <: Plugin
i = findfirst(p -> p isa T, t.plugins) i = findfirst(p -> p isa T, t.plugins)
i === nothing ? nothing : t.plugins[i] return i === nothing ? nothing : t.plugins[i]
end end
# Get a keyword, or compute some default value. # Get a keyword or a default value.
getkw(kwargs, k) = get(() -> defaultkw(Template, k), kwargs, k) getkw!(kwargs, k) = pop!(kwargs, k, defaultkw(Template, k))
# Default Template keyword values. # Default Template keyword values.
defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s)) defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s))

View File

@ -3,7 +3,7 @@ using Base.Filesystem: contractuser, path_separator
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo
using Pkg: Pkg using Pkg: Pkg
using Random: Random using Random: Random
using Test: @test, @testset, @test_throws using Test: @test, @testset, @test_logs, @test_throws
using ReferenceTests: @test_reference using ReferenceTests: @test_reference
using SimpleMock: mock using SimpleMock: mock

View File

@ -43,6 +43,11 @@
# Disabling a default plugin. # Disabling a default plugin.
test_plugins([], setdiff(defaults, [default_g]), [Git]) test_plugins([], setdiff(defaults, [default_g]), [Git])
end end
@testset "Unsupported keywords warning" begin
@test_logs tpl()
@test_logs (:warn, "Unrecognized keywords were supplied") tpl(; x=1, y=2)
end
end end
@testset "hasplugin" begin @testset "hasplugin" begin