#config-file #flags #lazy-evaluation #file #loader #file-format #config

lazyf

A simple means for grabbing config from flags and config files with a lazy, human readable, file format

5 releases

Uses old Rust 2015

0.1.4 Oct 30, 2018
0.1.3 Aug 20, 2018
0.1.2 Jun 21, 2018
0.1.1 Jun 18, 2018
0.1.0 Jun 16, 2018

#78 in #loader

MIT license

16KB
458 lines

Lazyf

A tool for setting up simple configuration in your program.

Changes:

//coming v 0.1.4: impl IntoIterator for &LzList Genericize Cfg load_first make easier to call

v 0.1.3:

Added a more correct error handling approach


lib.rs:

Lazyf

Lazyf is both a file format, and a mechanism for loading configurations. It's primary aim is to allow the user to be as lazy as possible when trying to get user options out of their code.

With lazyf user options come from two places. -Flags and config files. The cfg (config) module combines the lzlist (lazyfile) module and the flag module

The lazyf file format basically looks like this (ignore quotes):

"
Superman:
    power:Flying
    age:29

Batman:
    power:Money
    age:40
";

The simplesy way to get config options is:

use lazyf::{Cfg,SGetter};

let cf = Cfg::load_first("-c",   &["--config-location--"]);
let age = cf.get_t_def(("-bman","Batman.age"),10);
//age == 40

In this config location will be the location specified after the flag -c or the first of the config locations to return a result. if none are found a Cfg is still returned, as flags can still be used.

No runtime deps