Scjrm.jl/src/default.jl

73 lines
1.5 KiB
Julia

#=
This file defines the default config parameters and provides a simple
way of crating a template config file.
=#
defaultconfig = """
\"\"\"Custom functions to run in certain circumstances.
Read the documentation to know which hooks are available.\"\"\"
Scjrm.sethooks!(Dict{Symbol,Function}())
"""
# TODO: you can use merge to have customization + defaults
eval(defaultconfig)
"""
Writes the config to the file `name`
"""
function writeconfig(name::String)
open(name, "w") do f
write(f, defaultconfig)
end
end
"""
Set the `hooks`. If you want to remove all the hooks and then set
the new one, you should call `empty!(Scjrm.hooks)` before.
"""
function sethooks!(h::Dict)
merge!(hooks, h)
end
"""
Add an `hook` to `hooks`.
"""
addhook!(s::Symbol, f::Function) = hooks[:pre_receive] = f
"""
Remove `hook` from `hooks`
"""
function rmhook!(s::Symbol)
# `hooks` is a `const`ant. So we:
# copy `hooks`
tmphooks = deepcopy(hooks)
# Remove `s` from the copy
pop!(tmphooks, s)
# Clear `hooks`
empty!(hooks)
# Merge the copy to the empty `hooks`
merge!(hooks, tmphooks)
end
function setlibraries!(l::Dict)
empty!(libraries)
merge!(libraries,l)
end
"""Change the current library.
If `existing` is false, don't verify the new library exists.
Returns the new library"""
function currentlibrary!(l::String; existing = true)
global currentlibrary, libraries
if l in keys(libraries)
currentlibrary = l
end
currentlibrary
end