Skip to content

Commit

Permalink
feat: 🎸 Implement update function and add to guide
Browse files Browse the repository at this point in the history
Create a update wrapper calling the internal Copier update. The
overwrite=true argument needs to be passed to mimic the CLI behaviour.
Updates the guide with specific information to update.

✅ Closes: #113
  • Loading branch information
abelsiqueira committed Jun 7, 2024
1 parent 6ce66ce commit e08e64f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/src/10-full-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,36 @@ Now, go to [Setting up your package](@ref) to check what you still need to confi

### [Updating](@id updating_package)

WIP. Tracked in issue #113.
To update the package, simply call

```julia-repl
julia> COPIERTemplate.update()
```

You will be asked the relevant questions of the package as if you had applied it.
The big differences are:

- It will only apply the things that are new since you last applied/updated
- It will remember previous answer.

!!! tip "Change previous answers"
You can change your previous answers. In other words, if you though something was not mature enough in the past, but you are more confident in that now, you can adopt it now.

As with the first application, you need to run `pre-commit run -a` to fix the unavoidable linting and formatting issues.
Check the modifications in the relevant linter and formatting files, if you changed them manually, before doing it, though.

```bash
pre-commit run -a
```

The underlying package `copier` will use `git` to apply the differences and it will overwrite whatever files it finds in the way.
Since `git` is mandatory, the changes will be left for you to review.

!!! warning "Review the changes"
I repeat, the changes will be left for you to review.
Don't just add them blindly, because some of your modifications can and will be overwritten.

If you need some help with undoing some of these changes, I recommend using a graphical interface.

## Setting up your package

Expand Down
20 changes: 20 additions & 0 deletions src/COPIERTemplate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ function generate(dst_path, data::Dict = Dict(); kwargs...)
generate("https://github.com/abelsiqueira/COPIERTemplate.jl", dst_path, data; kwargs...)
end

"""
update([data]; kwargs...)
update(dst_path[, data]; kwargs...)
Run the update command of copier, updating the `dst_path` (or the current path if omitted) with a new version of the template with a new version of the template.
The `data` argument is a dictionary of answers (values) to questions (keys) that can be used to bypass some of the interactive questions.
## Keyword arguments
The keyword arguments are passed directly to the internal [`Copier.update`](@ref).
"""
function update(dst_path, data::Dict = Dict(); kwargs...)
Copier.update(dst_path, data; overwrite = true, kwargs...)
end

function update(data::Dict = Dict(); kwargs...)
Copier.update(".", data; overwrite = true, kwargs...)

Check warning on line 72 in src/COPIERTemplate.jl

View check run for this annotation

Codecov / codecov/patch

src/COPIERTemplate.jl#L71-L72

Added lines #L71 - L72 were not covered by tests
end

"""
data = _read_data_from_existing_path(dst_path)
Expand Down
28 changes: 28 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ end
end
end

@testset "Compare COPIERTemplate.update vs copier CLI update" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --defaults --quiet $min_bash_args $template_url $dir_copier_cli`)
cd(dir_copier_cli) do
run(`git init`)
run(`git add .`)
run(`git config user.name "Test"`)
run(`git config user.email "[email protected]"`)
run(`git commit -q -m "First commit"`)
end
run(`copier update --defaults --quiet $bash_args $dir_copier_cli`)

mktempdir(TMPDIR; prefix = "update_") do tmpdir
COPIERTemplate.generate(tmpdir, template_minimum_options; defaults = true, quiet = true)
cd(tmpdir) do
run(`git init`)
run(`git add .`)
run(`git config user.name "Test"`)
run(`git config user.email "[email protected]"`)
run(`git commit -q -m "First commit"`)
end
COPIERTemplate.update(tmpdir, template_options; defaults = true, quiet = true)

test_diff_dir(tmpdir, dir_copier_cli)
end
end
end

@testset "Testing copy, recopy and rebase" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --quiet $bash_args $template_path $dir_copier_cli`)
Expand Down

0 comments on commit e08e64f

Please sign in to comment.