Multi-configuration parser library using C

libnereon is a multi-configuration parser library implemented in C.
The configuration for the library is parsed in this order:

  • The command-line arguments.
  • The environment variables.
  • The configuration files based on HCL.

This library uses libucl.

HCL options for libnereon

HCL options have configuration model to specify command-line arguments, environment variables and configuration fields.
Here is an example:


log_directory {
	type = "string"
	cmdline "switch" {
		short = "l"
		long = "log-dir"
	}

	cmdline "description" {
		short = "log directory"
		long = "Specify the path of log directory"
	}

	env = "KAOHI_LOG_DIR"
	config = "global.log_directory"
}

listen_address {
	type = "ipport"
	cmdline "switch" {
		short = "L"
		long = "listen"
	}

	cmdline "description" {
		short = "IP:port"
		long = "Specify the listening address for Kaohi console"
	}

	env = "KAOHI_LISTEN_ADDR"
	config = "global.listen_address"
}

help {
	type = "bool"
	cmdline "switch {
		short = "h"
		long = "help"
	}

	cmdline "description" {
		short = ""
		long = "Print help message"
	}

	helper = true
}

  • type: the type of configuration value. It has int, string, bool, array, ipport, float.
  • switch: the command-line switch.
  • description: text message to describe each command-line option.
  • env: the environment variable to set configuration.
  • config: the keyword to specify an field in configuration file.
  • helper: the flag to print help message.

libnereon API functions

All API functions are defined in mconfig.h.