Skip to content

JuliaComputing/EasyConfig.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status Codecov deps version pkgeval

EasyConfig

  • EasyConfig provides a friendly-syntax, nested AbstractDict{Symbol, Any} data structure.
  • The advantages over other AbstractDict/NamedTuples are:

1) Intermediate levels are created on the fly:

  • This is quite convenient for working with JSON specs (e.g. PlotlyLight.jl).
c = Config()
c.one.two.three = 1

  • Compare this to OrderedDict and NamedTuple:
c = OrderedDict(:one => OrderedDict(:two => OrderedDict(:three => 1)))

c = (one = (two = (three = 1,),),)

c = (; one = (;two = (;three = 1)))



2) Easy to Use Both Interactively and Programmatically

  • You can use any combination of String/Symbol with getproperty/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"



@config

Create a Config with a NamedTuple-like or block syntax. The following examples create equivalent Configs:

@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

Note

  • Accessing a property that doesn't exist will create an empty Config().
  • Clean up stranded empty Configs with delete_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