diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index ec8f53a..a1886c2 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -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, diff --git a/src/plugin.jl b/src/plugin.jl index 00fddc9..52fd04c 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -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")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 825448a..0b2b41b 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -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. diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 805d446..fcb8e6f 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -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 diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 448cc36..58b4cae 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -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 diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index b450013..fcfe5b5 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -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}(), diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 06e93f6..c1ec679 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -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 diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index d4aca5b..c277f62 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -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 diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index 1f07a29..38b9acc 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -6,7 +6,7 @@ Creates a module entrypoint. ## Keyword Arguments - `file::AbstractString`: Template file for `src/.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", ".jl") end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 8281be6..1dc4684 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -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