Rename interactive to interactive_template, add docs

This commit is contained in:
Chris de Graaf 2017-08-21 16:19:40 -05:00
parent ab5b9e0033
commit 580e1c212c
8 changed files with 44 additions and 15 deletions

View File

@ -93,6 +93,10 @@ test/runtests.jl
Information on each keyword as well as plugin types can be found in the
[documentation](https://christopher-dG.github.io/PkgTemplates.jl/stable).
If that looks like a lot of work, you can also create templates interactively:
[![asciicast](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8.png)](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8)
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.

View File

@ -53,6 +53,10 @@ generate("MyPkg", t; force=true, ssh=true)
cd(joinpath(t.dir, "MyPkg")); run(`git ls-tree -r --name-only HEAD`)
```
If that looks like a lot of work, you can also create templates interactively:
[![asciicast](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8.png)](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8)
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.

View File

@ -11,6 +11,7 @@ Creating new packages with `PkgTemplates` revolves around creating a new
```@docs
Template
interactive_template
```
## `generate`

View File

@ -27,8 +27,12 @@ CustomPlugin
```@docs
gen_plugin
interactive
```
**Note**: `interactive` is not strictly required, however without it, your custom plugin
will not be available when creating templates with [`interactive_template`](@ref).
#### `badges`
```@docs

View File

@ -5,8 +5,8 @@ using Mustache
using TerminalMenus
using URIParser
export generate, interactive, show_license, Template, GitHubPages, AppVeyor, TravisCI,
CodeCov, Coveralls
export generate, interactive_template, show_license, Template, GitHubPages, AppVeyor,
TravisCI, CodeCov, Coveralls
abstract type Plugin end

View File

@ -8,6 +8,9 @@ Generic plugins are plugins that add any number of patterns to the generated pac
* `src::Nullable{AbstractString}`: Path to the file that will be copied into the generated
package repository. If set to `nothing`, no file will be generated. When this defaults
to an empty string, there should be a default file in `defaults` that will be copied.
That file's name is usually the same as the plugin's name, except in all lowercase and
with the `.yml` extension. If this is not the case, an `interactive` method needs to be
implemented to call `interactive(; file="other-filename.ext")`.
* `dest::AbstractString`: Path to the generated file, relative to the root of the generated
package repository.
* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to
@ -28,7 +31,7 @@ Generic plugins are plugins that add any number of patterns to the generated pac
function MyPlugin(; config_file::Union{AbstractString, Void}="")
if config_file != nothing
if isempty(config_file)
config_file = joinpath(DEFAULTS_DIR, "myplugin.yml")
config_file = joinpath(DEFAULTS_DIR, "my-plugin.toml")
elseif !isfile(config_file)
throw(ArgumentError(
"File \$(abspath(config_file)) does not exist"
@ -46,15 +49,19 @@ Generic plugins are plugins that add any number of patterns to the generated pac
"https://myplugin.com/{{USER}}/{{PKGNAME}}.jl",
),
],
Dict{String, Any}("YEAR" => Dates.year(Dates.now())),
Dict{String, Any}("YEAR" => Dates.year(now()),
)
end
end
interactive(plugin_type::Type{MyPlugin}) = interactive(plugin_type; file="my-plugin.toml")
```
The above plugin ignores files ending with `.mgp`, copies `defaults/myplugin.yml` by
The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by
default, and creates a badge that links to the project on its own site, using the default
substitutions with one addition: `{{YEAR}} => Dates.year(Dates.now())`.
substitutions with one addition: `{{YEAR}} => Dates.year(now()`. Since the default
config template file doesn't follow the generic naming convention, we added another
`interactive` method to correct the assumed filename.
"""
abstract type GenericPlugin <: Plugin end
@ -193,6 +200,16 @@ function badges(plugin::GenericPlugin, user::AbstractString, pkg_name::AbstractS
return [substitute(format(badge), view) for badge in plugin.badges]
end
"""
interactive(
plugin_type::Type{P <: Plugin};
file::Union{AbstractString, Void},
) -> Union{Plugin, Void}
Interactively create a plugin of type `plugin_type`, where `file` is the plugin type's
default config template with a non-standard name (for `MyPlugin`, this is anything but
"myplugin.yml").
"""
function interactive(
plugin_type::Type{P};
file::Union{AbstractString, Void}="",

View File

@ -65,6 +65,6 @@ function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractS
end
function interactive(plugin_type::Type{GitHubPages})
print("Enter any Documenter assets files for GitHubPages (separated by spaces) []")
print("Enter any Documenter asset files for GitHubPages (separated by spaces) []: ")
return GitHubPages(; assets=String.(split(readline())))
end

View File

@ -2,7 +2,7 @@
Template(; kwargs...) -> Template
Records common information used to generate a package. If you don't wish to manually
create a template, you can use [`interactive`](@ref) instead.
create a template, you can use [`interactive_template`](@ref) instead.
# Keyword Arguments
* `user::AbstractString="")`: GitHub username. If left unset, it will try to take the
@ -122,10 +122,10 @@ end
"""
interactive_template() -> Template
Interactively generate a [`Template`](@ref).
Interactively create a [`Template`](@ref).
"""
function interactive()
info("Generating template... default values are shown in [brackets]")
function interactive_template()
info("Default values are shown in [brackets]")
# Getting the leaf types in a separate thread eliminates an awkward wait after
# "Select plugins" is printed.
plugin_types = @spawn leaves(Plugin)
@ -197,13 +197,12 @@ function interactive()
kwargs[:git_config] = git_config
println("Select plugins:")
plugin_types = fetch(plugin_types)
# Only include plugin types which have an `interactive` method.
plugin_types = filter(t -> method_exists(interactive, (Type{t},)), fetch(plugin_types))
type_names = map(t -> split(string(t), ".")[end], plugin_types)
menu = MultiSelectMenu(String.(type_names); pagesize=length(type_names))
selected = collect(request(menu))
kwargs[:plugins] = Vector{Plugin}(
map(t -> interactive(t), getindex(plugin_types, selected)),
)
kwargs[:plugins] = map(t -> interactive(t), getindex(plugin_types, selected))
return Template(; kwargs...)
end