Code Monkey home page Code Monkey logo

confy's Introduction

confy

A C++17 application configuration library which is:

  • Easy to use
  • Configurable
  • Extensible

Although usable for the most part, the library is still in development. It's close to version v1.0.0. The progress towards v1.0.0 can be followed here

The gist

A short example:

    struct app_configuration
    {
        std::string name;
        int age = 0;
        enum class role_t
        {
            ceo, employee, intern
        };
        role_t role = role_t::intern;
    };

    // ...

    app_configuration c;

    confy::config cfg;
    cfg.schema()
        .opt(c.name, "name", "n", "The name of the person")
        .opt(c.age, "age", "a", "The age of the person")
        .opt(c.role, "role", "r", "The role of the person");

    cfg.parse_cmd_line(argc, argv);

    std::cout
        << "Name: " << c.name
        << "\nAge: " << c.age
        << "\nRole: " << confy::magic_enum::enum_name(c.role)
        << "\n";

It might seem that confy is Yet Another™ command line argument parser, but although it can be used as such, that's not its main power. It's configuration. If some of the options are not provided from the command line, it will search environment variables with that name and try to load values from there. The library also supports parsing of .ini files.

Each option in the schema tries to get it's value from the following sources (top has the highest priority):

  • Manual user override
  • Command line
  • Config (.ini) file
  • Environment variable
  • User-provided default fallback

The library is highly configurable by its schema-definition EDSL and can be extended with various user-defined option types (ie a point) and value sources (ie a .json file).

Building

You can use CMake. There is no special configuration involved to simply build the library.

Contributing

All contributions in the form of issues and pull requests are welcome.

Development

In order to buld the tests, you have to fetch the doctest submodule.

License

The library is distributed under the MIT Software License. See LICENSE.txt for further details or copy here.

Copyright © 2020-2021 Borislav Stanimirov.

confy embeds Magic Enum, © 2019-2020 Daniil Goncharov, which also under the MIT Softwre License.

confy's People

Contributors

ibob avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

blockspacer

confy's Issues

ini_file command

Add a command which can load .ini files from the command line

Implement config_exception

The idea is to optionally allow config to throw an exception when parsing options done (instead of expecting the users to check for errors at the end). The exception should contain a copy of the errors

help command

Add a command which displays the schema and requests parsing termination

Tests 1.0

Implement tests for the current features

  • config setup
  • Schema building
  • Parsing options

Single header build

Create a script which generates a single header library from confy (it's likely that this will be the preferred way to use it)

Documentation 1.0

Create markdown files in the doc subdirectory

  • Basic usage
  • Configuration
  • Extending

Create examples of features

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.