Start implementing the interactive plugin constructors

This commit is contained in:
Chris de Graaf 2019-09-26 17:56:16 +07:00
parent 17e3927eb1
commit 3f886525a7
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
10 changed files with 43 additions and 13 deletions

View File

@ -11,7 +11,7 @@ using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
using UUIDs: uuid4
using Mustache: render
using Parameters: @with_kw_noshow
using Parameters: with_kw
export
Template,

View File

@ -235,6 +235,36 @@ If you are implementing a plugin that uses the `user` field of a [`Template`](@r
"""
needs_username(::Plugin) = false
"""
@with_defaults struct T #= ... =# end
Wraps Parameters.jl's [`@with_kw_noshow`](https://mauro3.github.io/Parameters.jl/stable/api/#Parameters.@with_kw_noshow-Tuple{Any}) to generate keyword constructors,
TODO explain prompt syntax.
## Example
```julia
struct Foo <: Plugin
file::String = "/dev/null" <- "Path to the file to use"
n::Int <- "This one has no default, but this is the interactive prompt"
xyz::String = "Without a prompt, defaultkw is not implemented for this field"
end
```
"""
macro with_defaults(ex::Expr)
T = esc(ex.args[2].args[1])
# TODO: Parse out `<- "prompt"` stuff.
funcs = map(filter(arg -> arg isa Expr && arg.head === :(=), ex.args[3].args)) do arg
name = QuoteNode(arg.args[1].args[1])
val = arg.args[2]
:(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(arg.args[2])))
end
return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...)
end
include(joinpath("plugins", "project_file.jl"))
include(joinpath("plugins", "src_dir.jl"))
include(joinpath("plugins", "tests.jl"))

View File

@ -44,7 +44,7 @@ Integrates your packages with [Travis CI](https://travis-ci.com).
- `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included).
$EXTRA_VERSIONS_DOC
"""
@with_kw_noshow struct TravisCI <: BasicPlugin
@with_defaults struct TravisCI <: BasicPlugin
file::String = default_file("travis.yml")
linux::Bool = true
osx::Bool = true
@ -113,7 +113,7 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl]
- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included).
$EXTRA_VERSIONS_DOC
"""
@with_kw_noshow struct AppVeyor <: BasicPlugin
@with_defaults struct AppVeyor <: BasicPlugin
file::String = default_file("appveyor.yml")
x86::Bool = false
coverage::Bool = true
@ -166,7 +166,7 @@ $EXTRA_VERSIONS_DOC
!!! note
Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl).
"""
@with_kw_noshow struct CirrusCI <: BasicPlugin
@with_defaults struct CirrusCI <: BasicPlugin
file::String = default_file("cirrus.yml")
image::String = "freebsd-12-0-release-amd64"
coverage::Bool = true
@ -215,7 +215,7 @@ See [`Documenter`](@ref) for more information.
!!! note
Nightly Julia is not supported.
"""
@with_kw_noshow struct GitLabCI <: BasicPlugin
@with_defaults struct GitLabCI <: BasicPlugin
file::String = default_file("gitlab-ci.yml")
coverage::Bool = true
# Nightly has no Docker image.

View File

@ -7,7 +7,7 @@ Creates a `CITATION.bib` file for citing package repositories.
- `file::AbstractString`: Template file for `CITATION.bib`.
- `readme::Bool`: Whether or not to include a section about citing in the README.
"""
@with_kw_noshow struct Citation <: BasicPlugin
@with_defaults struct Citation <: BasicPlugin
file::String = default_file("CITATION.bib")
readme::Bool = false
end

View File

@ -8,7 +8,7 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io).
## Keyword Arguments
- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file.
"""
@with_kw_noshow struct Codecov <: BasicPlugin
@with_defaults struct Codecov <: BasicPlugin
file::Union{String, Nothing} = nothing
end
@ -29,7 +29,7 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io).
## Keyword Arguments
- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file.
"""
@with_kw_noshow struct Coveralls <: BasicPlugin
@with_defaults struct Coveralls <: BasicPlugin
file::Union{String, Nothing} = nothing
end

View File

@ -38,7 +38,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin
make_jl::String
index_md::String
# Can't use @with_kw_noshow due to some weird precompilation issues.
# Can't use @with_defaults due to some weird precompilation issues.
function Documenter{T}(;
assets::Vector{<:AbstractString}=String[],
makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(),

View File

@ -12,7 +12,7 @@ Creates a Git repository and a `.gitignore` file.
- `gpgsign::Bool`: Whether or not to sign commits with your GPG key.
This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity.
"""
@with_kw_noshow struct Git <: Plugin
@with_defaults struct Git <: Plugin
ignore::Vector{String} = []
ssh::Bool = false
manifest::Bool = false

View File

@ -14,7 +14,7 @@ By default, it includes badges for other included plugins
For example, values of `"README"` or `"README.rst"` might be desired.
- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name.
"""
@with_kw_noshow struct Readme <: BasicPlugin
@with_defaults struct Readme <: BasicPlugin
file::String = default_file("README.md")
destination::String = "README.md"
inline_badges::Bool = false

View File

@ -6,7 +6,7 @@ Creates a module entrypoint.
## Keyword Arguments
- `file::AbstractString`: Template file for `src/<module>.jl`.
"""
@with_kw_noshow mutable struct SrcDir <: BasicPlugin
@with_defaults mutable struct SrcDir <: BasicPlugin
file::String = default_file("src", "module.jl")
destination::String = joinpath("src", "<module>.jl")
end

View File

@ -14,7 +14,7 @@ Sets up testing for packages.
!!! note
Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later.
"""
@with_kw_noshow struct Tests <: BasicPlugin
@with_defaults struct Tests <: BasicPlugin
file::String = default_file("test", "runtests.jl")
project::Bool = false
end