All Projects → CJLove → config-cpp

CJLove / config-cpp

Licence: Apache-2.0 license
C++ Configuration management library inspired by the Viper package for golang.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to config-cpp

climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-4.76%)
Mutual labels:  yaml, toml, environment-variables, configuration-files
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+309.52%)
Mutual labels:  yaml, toml, environment-variables, configuration-files
Fig
A minimalist Go configuration library
Stars: ✭ 142 (+576.19%)
Mutual labels:  yaml, toml, environment-variables
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (+33.33%)
Mutual labels:  yaml, toml, environment-variables
paerser
No description or website provided.
Stars: ✭ 38 (+80.95%)
Mutual labels:  yaml, toml, environment-variables
Ansible Config encoder filters
Ansible role used to deliver the Config Encoder Filters.
Stars: ✭ 48 (+128.57%)
Mutual labels:  yaml, toml
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (+128.57%)
Mutual labels:  yaml, toml
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+271.43%)
Mutual labels:  yaml, toml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (+342.86%)
Mutual labels:  yaml, toml
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (+438.1%)
Mutual labels:  yaml, toml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+8509.52%)
Mutual labels:  yaml, toml
Configr
Implements the JSON, INI, YAML and TOML parser, for R setting and writing of configuration file.
Stars: ✭ 38 (+80.95%)
Mutual labels:  yaml, toml
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+971.43%)
Mutual labels:  yaml, toml
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (+180.95%)
Mutual labels:  yaml, toml
Parameterhandler
Composer script handling your ignored parameter file
Stars: ✭ 906 (+4214.29%)
Mutual labels:  yaml, environment-variables
Hugo Elasticsearch
Generate Elasticsearch indexes for Hugo static sites by parsing front matter
Stars: ✭ 19 (-9.52%)
Mutual labels:  yaml, toml
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+871.43%)
Mutual labels:  yaml, toml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+971.43%)
Mutual labels:  yaml, toml
jsonargparse
Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
Stars: ✭ 168 (+700%)
Mutual labels:  environment-variables, configuration-files
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+29328.57%)
Mutual labels:  yaml, toml

Build Status Coverage Status CodeQL

config-cpp

C++ Configuration library patterned after viper package for golang. It is designed to work within an application and handle configuration needs.

  • framework for companion libraries which can read from JSON, YAML, TOML
  • unmarshalling configuration data to native C++ types where supported
  • setting defaults
  • TODO: reading from environment variables
  • reading from command line flags
  • live watching and re-reading of config files or Kubernetes ConfigMaps

ConfigCpp uses the following precedence order. Each item takes precedence over the item(s) below it:

  • command-line flags
  • TODO: environment variables
  • configuration file
  • default

Dependencies

Also one or more of the following:

Basic Usage

Reading Config Files

ConfigCpp::ConfigCpp config;
config.SetConfigName("config"); // Name of config file minus extension
config.AddConfigPath("/etc/appname/"); // Path to look for config files
config.AddConfigPath("/home/.appname/"); // call as many times as needed
config.AddConfigPath(".");
if (!config.ReadInConfig()) {
    std::cerr << "Failed to read in config\n";
}

Watching and Re-reading Config Files

// Callback function called upon config file change
void onConfigChange(ConfigCpp::ConfigCpp &config) {
    std::cout << "Config changed\n";
    config.ReadInConfig();
    ...
}

config.OnConfigChange(onConfigChange);
config.WatchConfig();

Setting Defaults

Default values can be specified for keys in case values aren't specified in config file(s), environment variables, or command-line flags.

config.SetDefault("key1",false);
config.SetDefault("key2",255);
config.SetDefault("key3",0.95);
config.SetDefault("logLevel", "trace");

Environment Variables

TBD

Command-line Flags

Command line flags can be added as follows, following the cxxopts convention of specifying the long name optionally preceded by the short name separated by a comma.

config.AddBoolOption("b,top-bool","Bool option");
config.AddIntOption("t,top-int","Integer option");
config.AddStringOption("s,top-string","String option");
config.AddDoubleOption("d,top-double","Double option");
config.AddStringOption("long-only","String option w/no short name");

By default a --help option is added, which will result in displaying the help output from cxxopts and then exiting with return code 1. Errors encountered while parsing command-line arguments will result displaying the error message and help output from cxxopts and then exiting with return code 1.

Retrieving Configuration Values

std::string stringVal = config.GetString("key");
bool flagVal = config.GetBool("key.subkey");
int intVal = config.GetInt("key.intVal");
double doubleVal = config.GetDouble("key.double");

Unmarshalling to native types

See the JSON, YAML and TOML libraries for requirements.

JsonType myJsonConfig;
if (config.UnmarshalJson<JsonType>(myJsonConfig)) {
    ...
}

YamlType myYamlConfig;
if (config.UnmarshalYaml<YamlType>(myYamlConfig)) {
    ...
}

TomlType myTomlConfig;
if (config.UnmarshalToml<TomlType>(myTomlConfig)) {
    ...
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].