#configuration #config #nccl

nccl

Minimal configuration file format and library

25 releases (15 stable)

Uses new Rust 2021

5.3.0 Apr 8, 2022
5.0.1 Oct 30, 2021
4.0.2 Oct 29, 2021
3.0.0 Oct 29, 2021
0.1.0 Jun 25, 2017

#14 in Configuration

Download history 10/week @ 2022-01-27 3/week @ 2022-02-03 3/week @ 2022-02-10 27/week @ 2022-02-17 6/week @ 2022-02-24 7/week @ 2022-03-03 45/week @ 2022-03-10 104/week @ 2022-03-17 5/week @ 2022-03-24 71/week @ 2022-03-31 82/week @ 2022-04-07 9/week @ 2022-04-14 14/week @ 2022-04-21 180/week @ 2022-04-28 145/week @ 2022-05-05 407/week @ 2022-05-12

747 downloads per month
Used in asteroid

MIT license

55KB
1K SLoC

nccl Rust

non-crap config language

It's as easy as five cents. Also not crap, which is kind of the point.

  • key/value bindings
  • flexible indentation (eat it, python!)
  • merging configurations together

Crates.io - Docs

No relation to nickel which is another very cool project.

Demo

(more comprehensive examples in the docs)

Simple

In rust:

fn main() {
    let source = std::fs::read_to_string("examples/config.nccl").unwrap();
    let config = nccl::parse_config(&source).unwrap();
    let ports = config["server"]["port"]
        .values()
        .map(|port| port.parse::<u16>())
        .collect::<Result<Vec<_>, _>>()
        .unwrap();
    assert_eq!(ports, vec![80, 443]);
}

config.nccl:

server
    domain
        example.com
        www.example.com
    port
        80
        443
    root
        /var/www/html

Internally, your configuration is a tree. There is no real distinction between keys and values, everything is a node.

Inheritance

Nccl lets you define your own configuration to inherit from. If a node is present in both, it will be merged.

inherit.nccl:

hello
    world
        panama
    friends
        doggos

sandwich
    meat
        bologne
        ham
    cheese
        provolone
        cheddar

inherit2.nccl:

hello
    world
        alaska
        neighbor
    friends
        John
        Alex

sandwich
    meat
        turkey
    cheese
        muenster

Result from parse_config_with:

hello
    world
        panama
        alaska
        neighbor
    friends
        doggos
        John
        Alex
sandwich
    meat
        bologne
        ham
        turkey
    cheese
        provolone
        cheddar
        muenster

Example config

# one major syntactical feature:

key
    value

# comments too

bool one
    t

bool too
    false

ints
    5280
    thirteen
    1738

dates
    2017-03-21
    20170321T234442+0400
    2017-03-21T23:44:42+04
    tomorrow

# this uses 3 spaces for the whole key
strings
   are bare words
   unless you want newlines
   in which case:
      "just\nuse quotes"
   "this is still valid"
   this """too"""

# this uses tabs for the whole key
lists
	juan
	deaux
	key
		value
	3
	false

indentation?
    must use the same for top-level values
    eg 2 or 4 spaces for one key
    or tabs for one key

Dependencies

~405–650KB
~13K SLoC