Rename interactive to interactive_template, add docs
This commit is contained in:
parent
ab5b9e0033
commit
580e1c212c
@ -93,6 +93,10 @@ test/runtests.jl
|
|||||||
Information on each keyword as well as plugin types can be found in the
|
Information on each keyword as well as plugin types can be found in the
|
||||||
[documentation](https://christopher-dG.github.io/PkgTemplates.jl/stable).
|
[documentation](https://christopher-dG.github.io/PkgTemplates.jl/stable).
|
||||||
|
|
||||||
|
If that looks like a lot of work, you can also create templates interactively:
|
||||||
|
|
||||||
|
[](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8)
|
||||||
|
|
||||||
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
|
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
|
||||||
|
|
||||||
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.
|
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.
|
||||||
|
@ -53,6 +53,10 @@ generate("MyPkg", t; force=true, ssh=true)
|
|||||||
cd(joinpath(t.dir, "MyPkg")); run(`git ls-tree -r --name-only HEAD`)
|
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:
|
||||||
|
|
||||||
|
[](https://asciinema.org/a/bqBwff05mI7Cl9bz7EqLPMKF8)
|
||||||
|
|
||||||
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
|
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
|
||||||
|
|
||||||
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.
|
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.
|
||||||
|
@ -11,6 +11,7 @@ Creating new packages with `PkgTemplates` revolves around creating a new
|
|||||||
|
|
||||||
```@docs
|
```@docs
|
||||||
Template
|
Template
|
||||||
|
interactive_template
|
||||||
```
|
```
|
||||||
|
|
||||||
## `generate`
|
## `generate`
|
||||||
|
@ -27,8 +27,12 @@ CustomPlugin
|
|||||||
|
|
||||||
```@docs
|
```@docs
|
||||||
gen_plugin
|
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`
|
#### `badges`
|
||||||
|
|
||||||
```@docs
|
```@docs
|
||||||
|
@ -5,8 +5,8 @@ using Mustache
|
|||||||
using TerminalMenus
|
using TerminalMenus
|
||||||
using URIParser
|
using URIParser
|
||||||
|
|
||||||
export generate, interactive, show_license, Template, GitHubPages, AppVeyor, TravisCI,
|
export generate, interactive_template, show_license, Template, GitHubPages, AppVeyor,
|
||||||
CodeCov, Coveralls
|
TravisCI, CodeCov, Coveralls
|
||||||
|
|
||||||
abstract type Plugin end
|
abstract type Plugin end
|
||||||
|
|
||||||
|
@ -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
|
* `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
|
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.
|
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
|
* `dest::AbstractString`: Path to the generated file, relative to the root of the generated
|
||||||
package repository.
|
package repository.
|
||||||
* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to
|
* `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}="")
|
function MyPlugin(; config_file::Union{AbstractString, Void}="")
|
||||||
if config_file != nothing
|
if config_file != nothing
|
||||||
if isempty(config_file)
|
if isempty(config_file)
|
||||||
config_file = joinpath(DEFAULTS_DIR, "myplugin.yml")
|
config_file = joinpath(DEFAULTS_DIR, "my-plugin.toml")
|
||||||
elseif !isfile(config_file)
|
elseif !isfile(config_file)
|
||||||
throw(ArgumentError(
|
throw(ArgumentError(
|
||||||
"File \$(abspath(config_file)) does not exist"
|
"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",
|
"https://myplugin.com/{{USER}}/{{PKGNAME}}.jl",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
Dict{String, Any}("YEAR" => Dates.year(Dates.now())),
|
Dict{String, Any}("YEAR" => Dates.year(now()),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
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
|
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]
|
return [substitute(format(badge), view) for badge in plugin.badges]
|
||||||
end
|
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(
|
function interactive(
|
||||||
plugin_type::Type{P};
|
plugin_type::Type{P};
|
||||||
file::Union{AbstractString, Void}="",
|
file::Union{AbstractString, Void}="",
|
||||||
|
@ -65,6 +65,6 @@ function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractS
|
|||||||
end
|
end
|
||||||
|
|
||||||
function interactive(plugin_type::Type{GitHubPages})
|
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())))
|
return GitHubPages(; assets=String.(split(readline())))
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Template(; kwargs...) -> Template
|
Template(; kwargs...) -> Template
|
||||||
|
|
||||||
Records common information used to generate a package. If you don't wish to manually
|
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
|
# Keyword Arguments
|
||||||
* `user::AbstractString="")`: GitHub username. If left unset, it will try to take the
|
* `user::AbstractString="")`: GitHub username. If left unset, it will try to take the
|
||||||
@ -122,10 +122,10 @@ end
|
|||||||
"""
|
"""
|
||||||
interactive_template() -> Template
|
interactive_template() -> Template
|
||||||
|
|
||||||
Interactively generate a [`Template`](@ref).
|
Interactively create a [`Template`](@ref).
|
||||||
"""
|
"""
|
||||||
function interactive()
|
function interactive_template()
|
||||||
info("Generating template... 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.
|
||||||
plugin_types = @spawn leaves(Plugin)
|
plugin_types = @spawn leaves(Plugin)
|
||||||
@ -197,13 +197,12 @@ function interactive()
|
|||||||
kwargs[:git_config] = git_config
|
kwargs[:git_config] = git_config
|
||||||
|
|
||||||
println("Select plugins:")
|
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)
|
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] = Vector{Plugin}(
|
kwargs[:plugins] = map(t -> interactive(t), getindex(plugin_types, selected))
|
||||||
map(t -> interactive(t), getindex(plugin_types, selected)),
|
|
||||||
)
|
|
||||||
|
|
||||||
return Template(; kwargs...)
|
return Template(; kwargs...)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user