Add backup_dir kwarg to generate
This commit is contained in:
parent
3ec33bc02c
commit
fcf435d7ec
@ -11,6 +11,8 @@ Generate a package names `pkg_name` from `template`.
|
|||||||
# Keyword Arguments
|
# Keyword Arguments
|
||||||
* `force::Bool=false`: Whether or not to overwrite old packages with the same name.
|
* `force::Bool=false`: Whether or not to overwrite old packages with the same name.
|
||||||
* `ssh::Bool=false`: Whether or not to use SSH for the remote.
|
* `ssh::Bool=false`: Whether or not to use SSH for the remote.
|
||||||
|
* `backup_dir::AbstractString=""`: Directory in which to store the generated package if
|
||||||
|
`t.dir` is not a valid directory. If left unset, a temporary directory will be created.
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
The package is generated entirely in a temporary directory and only moved into
|
The package is generated entirely in a temporary directory and only moved into
|
||||||
@ -23,9 +25,10 @@ function generate(
|
|||||||
t::Template;
|
t::Template;
|
||||||
force::Bool=false,
|
force::Bool=false,
|
||||||
ssh::Bool=false,
|
ssh::Bool=false,
|
||||||
|
backup_dir::AbstractString="",
|
||||||
)
|
)
|
||||||
mktempdir() do temp_dir
|
mktempdir() do temp_dir
|
||||||
generate(pkg_name, t, temp_dir; force=force, ssh=ssh)
|
generate(pkg_name, t, temp_dir; force=force, ssh=ssh, backup_dir=backup_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ function generate(
|
|||||||
dir::AbstractString;
|
dir::AbstractString;
|
||||||
force::Bool=false,
|
force::Bool=false,
|
||||||
ssh::Bool=false,
|
ssh::Bool=false,
|
||||||
|
backup_dir::AbstractString="",
|
||||||
)
|
)
|
||||||
pkg_name = Pkg.splitjl(pkg_name)
|
pkg_name = Pkg.splitjl(pkg_name)
|
||||||
pkg_dir = joinpath(t.dir, pkg_name)
|
pkg_dir = joinpath(t.dir, pkg_name)
|
||||||
@ -92,11 +96,16 @@ function generate(
|
|||||||
try
|
try
|
||||||
mkpath(dirname(pkg_dir))
|
mkpath(dirname(pkg_dir))
|
||||||
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
|
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
|
||||||
catch # Likely cause is that t.path can't be created (is a file, etc.).
|
catch # Likely cause is that t.dir can't be created (is a file, etc.).
|
||||||
# We need another temporary directory because temp_pkg_dir is about to be removed.
|
# We're just going to trust that backup_dir is a valid directory.
|
||||||
temp_dir = mktempdir()
|
backup_dir = if isempty(backup_dir)
|
||||||
mv(temp_pkg_dir, joinpath(temp_dir, pkg_name))
|
mktempdir()
|
||||||
warn("$pkg_name couldn't be moved into $pkg_dir, left package in $temp_dir")
|
else
|
||||||
|
abspath(backup_dir)
|
||||||
|
end
|
||||||
|
mkpath(backup_dir)
|
||||||
|
mv(temp_pkg_dir, joinpath(backup_dir, pkg_name))
|
||||||
|
warn("$pkg_name couldn't be moved into $pkg_dir, left package in $backup_dir")
|
||||||
end
|
end
|
||||||
|
|
||||||
info("Finished")
|
info("Finished")
|
||||||
|
@ -381,13 +381,16 @@ end
|
|||||||
@test isfile(Pkg.dir(test_pkg, "README.md"))
|
@test isfile(Pkg.dir(test_pkg, "README.md"))
|
||||||
rm(Pkg.dir(test_pkg); recursive=true)
|
rm(Pkg.dir(test_pkg); recursive=true)
|
||||||
|
|
||||||
# Note: These tests will leave temporary directories on disk.
|
|
||||||
temp_file, fd = mktemp()
|
temp_file, fd = mktemp()
|
||||||
close(fd)
|
close(fd)
|
||||||
|
temp_dir = mktempdir()
|
||||||
t = Template(; user=me, dir=temp_file, gitconfig=gitconfig)
|
t = Template(; user=me, dir=temp_file, gitconfig=gitconfig)
|
||||||
@test_warn r".+" generate(test_pkg, t)
|
@test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir)
|
||||||
|
rm(temp_dir; recursive=true)
|
||||||
|
temp_dir = mktempdir()
|
||||||
t = Template(; user=me, dir=joinpath(temp_file, "file"), gitconfig=gitconfig)
|
t = Template(; user=me, dir=joinpath(temp_file, "file"), gitconfig=gitconfig)
|
||||||
@test_warn r".+" generate(test_pkg, t)
|
@test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir)
|
||||||
|
rm(temp_dir; recursive=true)
|
||||||
rm(temp_file)
|
rm(temp_file)
|
||||||
|
|
||||||
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
|
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
|
||||||
|
Loading…
Reference in New Issue
Block a user