@@ -34,20 +34,48 @@ function def_kwconstructor(T, propertynames)
3434end
3535
3636const BATTERIES_DEFAULTS = (
37- eq= true , hash= true ,
38- kwconstructor= false , kwshow= false ,
39- getproperties= true , constructorof= true ,
37+ eq = true ,
38+ hash = true ,
39+ kwconstructor = false ,
40+ kwshow = false ,
41+ getproperties = true ,
42+ constructorof = true ,
4043)
4144
45+ const BATTERIES_DOCSTRINGS = (
46+ eq = " Define `Base.(==)` structurally." ,
47+ hash = " Define `Base.hash` structurally." ,
48+ kwconstructor = " Add a keyword constructor." ,
49+ kwshow = " Overload `Base.show` such that the names of each field are printed." ,
50+ getproperties = " Overload `ConstructionBase.getproperties`." ,
51+ constructorof = " Overload `ConstructionBase.constructorof`." ,
52+ )
53+
54+ if (keys (BATTERIES_DEFAULTS) != keys (BATTERIES_DOCSTRINGS))
55+ error ("""
56+ keys(BATTERIES_DEFAULTS) == key(BATTERIES_DOCSTRINGS) must hold.
57+ Got:
58+ keys(BATTERIES_DEFAULTS) = $(keys (BATTERIES_DEFAULTS))
59+ keys(BATTERIES_DOCSTRINGS) = $(keys (BATTERIES_DOCSTRINGS))
60+ """ )
61+ end
62+ @assert keys (BATTERIES_DEFAULTS) == keys (BATTERIES_DOCSTRINGS)
63+
64+ function doc_batteries_options ()
65+ lines = map (propertynames (BATTERIES_DEFAULTS)) do key
66+ " * **$key ** = $(BATTERIES_DEFAULTS[key]) :\n $(BATTERIES_DOCSTRINGS[key]) "
67+ end
68+ join (lines, " \n " )
69+ end
70+
71+
4272const ALLOWED_KW = keys (BATTERIES_DEFAULTS)
4373
4474"""
4575
4676 @batteries T [options]
4777
4878Automatically derive several methods for type `T`.
49- Supported options are:
50- $BATTERIES_DEFAULTS
5179
5280# Example
5381```julia
6088@batteries S hash=false # don't overload `Base.hash`
6189@batteries S kwconstructor=true # add a keyword constructor
6290```
91+
92+ Supported options and defaults are:
93+
94+ $(doc_batteries_options ())
6395"""
6496macro batteries (T, kw... )
6597 nt = parse_all_macro_kw (kw)
0 commit comments