Add fast keyword to interactive_template

This commit is contained in:
Chris de Graaf 2017-08-22 13:49:24 -05:00
parent 7bba20e60c
commit f390a2434f

View File

@ -120,11 +120,12 @@ don't belong.
end end
""" """
interactive_template() -> Template interactive_template(; fast::Bool) -> Template
Interactively create a [`Template`](@ref). Interactively create a [`Template`](@ref). If `fast` is set, defaults will be assumed for
all values except username and plugins.
""" """
function interactive_template() function interactive_template(; fast::Bool=false)
info("Default values are shown in [brackets]") info("Default values are shown in [brackets]")
# Getting the leaf types in a separate thread eliminates an awkward wait after # Getting the leaf types in a separate thread eliminates an awkward wait after
# "Select plugins" is printed. # "Select plugins" is printed.
@ -142,48 +143,75 @@ function interactive_template()
throw(ArgumentError("Username is required")) throw(ArgumentError("Username is required"))
end end
kwargs[:host] = if fast
"https://github.com"
else
default_host = "github.com" default_host = "github.com"
print("Enter the code hosting service [$default_host]: ") print("Enter the code hosting service [$default_host]: ")
host = readline() host = readline()
kwargs[:host] = isempty(host) ? default_host : host isempty(host) ? default_host : host
end
kwargs[:license] = if fast
"MIT"
else
println("Select a license:") println("Select a license:")
io = IOBuffer() io = IOBuffer()
show_license(; io=io) show_license(; io=io)
licenses = [nothing => nothing, collect(LICENSES)...] licenses = [nothing => nothing, collect(LICENSES)...]
menu = RadioMenu(["None", split(String(take!(io)), "\n")...]) menu = RadioMenu(["None", split(String(take!(io)), "\n")...])
# If the user breaks out of the menu with C-c, the result is -1, the absolute value of # If the user breaks out of the menu with C-c, the result is -1, the absolute
# which correponds to no license. # value of which correponds to no license.
kwargs[:license] = licenses[abs(request(menu))].first licenses[abs(request(menu))].first
end
kwargs[:authors] = if fast
LibGit2.getconfig("user.name", "")
else
default_authors = LibGit2.getconfig("user.name", "") default_authors = LibGit2.getconfig("user.name", "")
default_str = isempty(default_authors) ? "None" : default_authors default_str = isempty(default_authors) ? "None" : default_authors
print("Enter the package author(s) [$default_str]: ") print("Enter the package author(s) [$default_str]: ")
authors = readline() authors = readline()
kwargs[:authors] = isempty(authors) ? default_authors : authors isempty(authors) ? default_authors : authors
end
kwargs[:years] = if fast
Dates.year(now())
else
default_years = Dates.year(now()) default_years = Dates.year(now())
print("Enter the copyright year(s) [$default_years]: ") print("Enter the copyright year(s) [$default_years]: ")
years = readline() years = readline()
kwargs[:years] = isempty(years) ? default_years : years isempty(years) ? default_years : years
end
kwargs[:dir] = if fast
Pkg.dir()
else
default_dir = Pkg.dir() default_dir = Pkg.dir()
print("Enter the path to the package directory [$default_dir]: ") print("Enter the path to the package directory [$default_dir]: ")
dir = readline() dir = readline()
kwargs[:dir] = isempty(dir) ? default_dir : dir isempty(dir) ? default_dir : dir
end
kwargs[:julia_version] = if fast
VERSION
else
default_julia_version = VERSION default_julia_version = VERSION
print("Enter the minimum Julia version [$default_julia_version]: ") print("Enter the minimum Julia version [$default_julia_version]: ")
julia_version = readline() julia_version = readline()
kwargs[:julia_version] = if isempty(julia_version) isempty(julia_version) ? default_julia_version : VersionNumber(julia_version)
default_julia_version
else
VersionNumber(julia_version)
end end
kwargs[:requirements] = if fast
String[]
else
print("Enter any Julia package requirements, (separated by spaces) []: ") print("Enter any Julia package requirements, (separated by spaces) []: ")
requirements = String.(split(readline())) String.(split(readline()))
end
kwargs[:git_config] = if fast
Dict()
else
git_config = Dict() git_config = Dict()
print("Enter any Git key-value pairs (one at a time, separated by spaces) [None]: ") print("Enter any Git key-value pairs (one at a time, separated by spaces) [None]: ")
while true while true
@ -194,7 +222,8 @@ function interactive_template()
end end
git_config[tokens[1]] = tokens[2] git_config[tokens[1]] = tokens[2]
end end
kwargs[:git_config] = git_config git_config
end
println("Select plugins:") println("Select plugins:")
# Only include plugin types which have an `interactive` method. # Only include plugin types which have an `interactive` method.
@ -202,7 +231,9 @@ function interactive_template()
type_names = map(t -> split(string(t), ".")[end], plugin_types) type_names = map(t -> split(string(t), ".")[end], plugin_types)
menu = MultiSelectMenu(String.(type_names); pagesize=length(type_names)) menu = MultiSelectMenu(String.(type_names); pagesize=length(type_names))
selected = collect(request(menu)) selected = collect(request(menu))
kwargs[:plugins] = map(t -> interactive(t), getindex(plugin_types, selected)) kwargs[:plugins] = Vector{Plugin}(
map(t -> interactive(t), getindex(plugin_types, selected))
)
return Template(; kwargs...) return Template(; kwargs...)
end end