Skip to content

Commit

Permalink
Simplify plugin collection for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG committed May 25, 2020
1 parent ba15a67 commit d8d1886
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions src/template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ defaultkw(::Type{Template}, ::Val{:julia}) = default_version()
defaultkw(::Type{Template}, ::Val{:plugins}) = Plugin[]
defaultkw(::Type{Template}, ::Val{:user}) = default_user()

customizable(::Type{Template}) = (:disable_defaults => Vector{DataType},)

function interactive(::Type{Template}; kwargs...)
# If the user supplied any keywords themselves, don't prompt for them.
kwargs = Dict{Symbol, Any}(kwargs)
Expand All @@ -196,17 +194,6 @@ function interactive(::Type{Template}; kwargs...)
kwargs[k] = prompt(Template, fieldtype(Template, k), k)
end

# We didn't include :disable_defaults above.
# Instead, the :plugins prompt pre-selected default plugins,
# so any default plugins that were explicitly excluded from the user's selection
# should be disabled.
if :plugins in customize && !haskey(kwargs, :disable_defaults)
plugin_types = map(typeof, kwargs[:plugins])
kwargs[:disable_defaults] = DataType[]
foreach(map(typeof, default_plugins())) do T
T in plugin_types || push!(kwargs[:disable_defaults], T)
end
end
return Template(; kwargs...)
end

Expand Down Expand Up @@ -249,7 +236,10 @@ function prompt(::Type{Template}, ::Type, ::Val{:plugins})
# To make this better, we need julia#30043.
print(stdin.buffer, (CR * DOWN)^ndefaults)
types = sort!(collect(request(menu)))
return map(interactive, options[types])
plugins = Vector{Any}(map(interactive, options[types]))
# Find any defaults that were disabled.
foreach(i -> i in types || push!(plugins, !defaults[i]), 1:ndefaults)
return plugins
end

# Call the default prompt method even if a specialized one exists.
Expand Down
2 changes: 1 addition & 1 deletion test/interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end
)
@test Template(; interactive=true) == Template(;
user=USER,
disable_defaults=[Readme, TagBot],
plugins=[!Readme, !TagBot],
)
readavailable(stdin.buffer)
end
Expand Down

0 comments on commit d8d1886

Please sign in to comment.