Skip to content

Commit

Permalink
Interactive mode (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG authored May 25, 2020
1 parent 3500258 commit 18c32a1
Show file tree
Hide file tree
Showing 33 changed files with 686 additions and 175 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/Manifest.toml
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ julia:
before_script:
- git config --global user.name Tester
- git config --global user.email te@st.er
script: travis_wait julia --project -e 'using Pkg; Pkg.test(coverage=true)'
matrix:
fast_finish: true
allow_failures:
Expand Down
115 changes: 0 additions & 115 deletions Manifest.toml

This file was deleted.

2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ version = "0.7.0-DEV"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Expand Down
27 changes: 13 additions & 14 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[DataAPI]]
git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.1.0"
version = "1.3.0"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand All @@ -29,9 +29,9 @@ version = "0.8.1"

[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "646ebc3db49889ffeb4c36f89e5d82c6a26295ff"
git-tree-sha1 = "395fa1554c69735802bba37d9e7d9586fd44326c"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.24.7"
version = "0.24.11"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -71,15 +71,14 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Mustache]]
deps = ["Printf", "Tables"]
git-tree-sha1 = "e06eef2abee113c49695f5347668e15d4c02978a"
git-tree-sha1 = "2e11fc5de3a01d23482a257e22009ddaab058d9a"
uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
version = "1.0.0"
version = "1.0.2"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"
version = "1.2.0"

[[Parameters]]
deps = ["OrderedCollections"]
Expand All @@ -89,16 +88,16 @@ version = "0.12.0"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "0c16b3179190d3046c073440d94172cfc3bb0553"
git-tree-sha1 = "f8f5d2d4b4b07342e5811d2b6428e45524e241df"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "0.3.12"
version = "1.0.2"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PkgTemplates]]
deps = ["Dates", "LibGit2", "Mustache", "Parameters", "Pkg", "UUIDs"]
deps = ["Dates", "InteractiveUtils", "LibGit2", "Mustache", "Parameters", "Pkg", "REPL", "UUIDs"]
path = ".."
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
version = "0.7.0-DEV"
Expand Down Expand Up @@ -132,9 +131,9 @@ version = "1.0.0"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591"
git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "0.2.11"
version = "1.0.4"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
Expand Down
30 changes: 25 additions & 5 deletions docs/src/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To understand how they're implemented, let's look at simplified versions of two
### Example: `Documenter`

```julia
@with_kw_noshow struct Documenter <: Plugin
@plugin struct Documenter <: Plugin
make_jl::String = default_file("docs", "make.jl")
index_md::String = default_file("docs", "src", "index.md")
end
Expand Down Expand Up @@ -117,10 +117,11 @@ function hook(p::Documenter, t::Template, pkg_dir::AbstractString)
end
```

The `@with_kw_noshow` macro defines keyword constructors for us.
The `@plugin` macro defines some helpful methods for us.
Inside of our struct definition, we're using [`default_file`](@ref) to refer to files in this repository.

```@docs
@plugin
default_file
```

Expand All @@ -138,7 +139,11 @@ Badge
```

These two functions, [`gitignore`](@ref) and [`badges`](@ref), are currently the only "special" functions for cross-plugin interactions.
In other cases, you can still access the [`Template`](@ref)'s plugins to depend on the presence/properties of other plugins, although that's less powerful.
In other cases, you can still access the [`Template`](@ref)'s plugins to depend on the presence/properties of other plugins via [`getplugin`](@ref), although that's less powerful.

```@docs
getplugin
```

Third, we implement [`view`](@ref), which is used to fill placeholders in badges and rendered files.

Expand Down Expand Up @@ -197,6 +202,7 @@ function posthook(::Git, ::Template, pkg_dir::AbstractString)
end
```

We didn't use `@plugin` for this one, because there are no fields.
Validation and all three hooks are implemented:

- [`validate`](@ref) makes sure that all required Git configuration is present.
Expand All @@ -217,7 +223,7 @@ In general, they just generate one templated file.
To illustrate, let's look at the [`Citation`](@ref) plugin, which creates a `CITATION.bib` file.

```julia
@with_kw_noshow struct Citation <: FilePlugin
@plugin struct Citation <: FilePlugin
file::String = default_file("CITATION.bib")
end

Expand Down Expand Up @@ -294,7 +300,7 @@ Of course, we could use a normal [`Plugin`](@ref), but it turns out there's a wa
The plugin implements its own `hook`, but uses `invoke` to avoid duplicating the file creation code:

```julia
@with_kw_noshow struct Tests <: FilePlugin
@plugin struct Tests <: FilePlugin
file::String = default_file("runtests.jl")
end

Expand All @@ -315,6 +321,20 @@ If you want to extend the validation but keep the file existence check, use the

For more examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections.

## Supporting Interactive Mode

When it comes to supporting interactive mode for your custom plugins, you have two options: write your own [`interactive`](@ref) method, or use the default one.
If you choose the first option, then you are free to implement the method however you want.
If you want to use the default implementation, then there are a few functions that you should be aware of, although in many cases you will not need to add any new methods.

```@docs
interactive
prompt
customizable
input_tips
convert_input
```

## Miscellaneous Tips

### Writing Template Files
Expand Down
7 changes: 5 additions & 2 deletions docs/src/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ One less name to remember!
| :-----------------------------------------: | :---------------------------------: |
| `generate(::Template, pkg::AbstractString)` | `(::Template)(pkg::AbstractString)` |

## Interactive Templates
## Interactive Mode

Currently not implemented, but will be in the future.
| Old | New |
| :-----------------------------------------: | :---------------------------------: |
| `interactive_template()` | `Template(; interactive=true)` |
| `generate_interactive(pkg::AbstractString)` | `Template(; interactive=true)(pkg)` |

## Other Functions

Expand Down
3 changes: 2 additions & 1 deletion docs/src/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ t("MyPkg")

```@docs
Template
generate
```

## Plugins
Expand All @@ -40,6 +41,7 @@ Tests
Readme
License
Git
CompatHelper
TagBot
Secret
```
Expand Down Expand Up @@ -76,7 +78,6 @@ Documenter

```@docs
Develop
CompatHelper
Citation
```

Expand Down
4 changes: 4 additions & 0 deletions src/PkgTemplates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module PkgTemplates
using Base: active_project, contractuser

using Dates: month, today, year
using InteractiveUtils: subtypes
using LibGit2: LibGit2, GitConfig, GitRemote, GitRepo
using Pkg: Pkg, TOML, PackageSpec
using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
using UUIDs: uuid4

using Mustache: render
Expand All @@ -25,6 +27,7 @@ export
GitHubActions,
GitLabCI,
License,
NoDeploy,
ProjectFile,
Readme,
Secret,
Expand All @@ -44,6 +47,7 @@ abstract type Plugin end
include("template.jl")
include("plugin.jl")
include("show.jl")
include("interactive.jl")
include("deprecated.jl")

# Run some function with a project activated at the given path.
Expand Down
1 change: 1 addition & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@deprecate interactive_template() Template(; interactive=true)
@deprecate generate_interactive(pkg::AbstractString) Template(; interactive=true)(pkg)
@deprecate GitHubPages(; kwargs...) Documenter{TravisCI}(; kwargs...)
@deprecate GitLabPages(; kwargs...) Documenter{GitLabCI}(; kwargs...)
Loading

0 comments on commit 18c32a1

Please sign in to comment.