Configurations.jl

Options & Configurations made easy.
Author Roger-luo
Popularity
18 Stars
Updated Last
1 Month Ago
Started In
October 2020

Configurations

CI codecov

Configurations & Options made easy.

Installation

Configurations is a   Julia Language   package. To install Configurations, please open Julia's interactive session (known as REPL) and press ] key in the REPL to use the package mode, then type the following command

pkg> add Configurations

Usage

There are more detailed guide in the documentation.

This package provides a macro @option to let you define structs to represent options/configurations, and serialize between different option/configuration file formats such as TOML.

You can easily create hierarchical struct types:

julia> using Configurations

julia> "Option A"
       @option "option_a" struct OptionA
           name::String
           int::Int = 1
       end

julia> "Option B"
       @option "option_b" struct OptionB
           opt::OptionA = OptionA(;name = "Sam")
           float::Float64 = 0.3
       end

and then convert from a Dict to your option type via from_dict:

julia> d = Dict{String, Any}(
           "opt" => Dict{String, Any}(
               "name" => "Roger",
               "int" => 2,
           ),
           "float" => 0.33
       );

julia> option = from_dict(OptionB, d)
OptionB(;
    opt = OptionA(;
        name = "Roger",
        int = 2,
    ),
    float = 0.33,
)

License

MIT License