- EasyConfig provides a friendly-syntax, nested
AbstractDict{Symbol, Any}
data structure. - The advantages over other
AbstractDict/NamedTuple
s are:
- This is quite convenient for working with JSON specs (e.g. PlotlyLight.jl).
c = Config()
c.one.two.three = 1
- Compare this to
OrderedDict
andNamedTuple
:
c = OrderedDict(:one => OrderedDict(:two => OrderedDict(:three => 1)))
c = (one = (two = (three = 1,),),)
c = (; one = (;two = (;three = 1)))
- You can use any combination of
String
/Symbol
withgetproperty
/getindex
. - For working interactively,
getproperty
is the most convenient to work with. - For working programmatically,
getindex
is the most convenient to work with.
# getproperty
c.one.two.three
# getindex
c[:one][:two][:three]
# mix and match
c["one"].two."three"
Create a Config
with a NamedTuple-like or block syntax. The following examples create equivalent Config
s:
@config (x.one=1, x.two=2, z=3)
@config x.one=1 x.two=2 z=3
@config begin
x.one = 1
x.two = 2
z = 3
end
let
c = Config()
c.x.one = 1
c.x.two = 2
c.z = 3
end
- Accessing a property that doesn't exist will create an empty
Config()
. - Clean up stranded empty
Config
s withdelete_empty!(::Config)
.
c = Config()
c.one.two.three.four.five.six == Config()
# Internally we make the assumption that empty Config's shouldn't be there.
# Some functions will therefore call `delete_empty!` under the hood:
isempty(c) == true