Merge pull request #76 from invenia/cdg/authors
Replace authors field in Project.toml
This commit is contained in:
commit
b865b9f422
@ -23,6 +23,14 @@ function generate(
|
||||
println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))")
|
||||
end
|
||||
|
||||
# Replace the authors field with the template's authors.
|
||||
if !isempty(t.authors)
|
||||
path = joinpath(pkg_dir, "Project.toml")
|
||||
project = read(path, String)
|
||||
authors = string("[", join(map(repr ∘ strip, split(t.authors, ",")), ", "), "]")
|
||||
write(path, replace(project, r"authors = .*" => "authors = $authors"))
|
||||
end
|
||||
|
||||
if git
|
||||
# Initialize the repo.
|
||||
repo = LibGit2.init(pkg_dir)
|
||||
|
@ -74,7 +74,9 @@ struct Template
|
||||
# If no author was set, look for one in the global git config.
|
||||
if isempty(authors)
|
||||
authors = LibGit2.getconfig("user.name", "")
|
||||
elseif isa(authors, Vector)
|
||||
email = LibGit2.getconfig("user.email", "")
|
||||
isempty(email) || (authors *= " <$email>")
|
||||
elseif authors isa Vector
|
||||
authors = join(authors, ", ")
|
||||
end
|
||||
|
||||
|
@ -39,10 +39,10 @@ write(test_file, template_text)
|
||||
|
||||
@testset "Template creation" begin
|
||||
# Checking default field assignments.
|
||||
t = Template(; user=me)
|
||||
t = Template(; authors="foo", user=me)
|
||||
@test t.user == me
|
||||
@test t.license == "MIT"
|
||||
@test t.authors == LibGit2.getconfig("user.name", "")
|
||||
@test t.authors == "foo"
|
||||
@test t.dir == default_dir
|
||||
@test t.julia_version == PkgTemplates.default_version()
|
||||
@test !t.ssh
|
||||
@ -109,14 +109,14 @@ end
|
||||
pkg_dir = replace(default_dir, homedir() => "~")
|
||||
ver = PkgTemplates.version_floor(PkgTemplates.default_version())
|
||||
buf = IOBuffer()
|
||||
t = Template(; user=me)
|
||||
t = Template(; user=me, authors="foo")
|
||||
show(buf, t)
|
||||
text = String(take!(buf))
|
||||
expected = """
|
||||
Template:
|
||||
→ User: $me
|
||||
→ Host: github.com
|
||||
→ License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today())))
|
||||
→ License: MIT (foo $(year(today())))
|
||||
→ Package directory: $pkg_dir
|
||||
→ Minimum Julia version: v$ver
|
||||
→ SSH remote: No
|
||||
|
Loading…
Reference in New Issue
Block a user