Git Product home page Git Product logo

d-simpleconfig's Introduction

Library primarily intended to help quickly write small command-line tools. Parses command-line arguments and configuration file and stores result into provided D struct instance.

Example

void main ()
{
    import simpleconfig;

    struct Config
    {
        @cli
        int value;
        @cli("flag|f") @cfg("flag")
        string anothervalue;
        @cfg("some ratio")
        double ratio;

        void finalizeConfig ()
        {

        }
    }

    Config config;
    readConfiguration(config);
}

This snippet will do the following:

  • Check standard locations for the current platform for the config file named appname.cfg. If found, parse it and initialize config.anothervalue from flag entry and config.ration from some ratio entry.
  • Iterate through command-line arguments. If --value argument is found, it will be written to config.value (using std.conv.to for conversion). If either --flag or -f arguments are found, it will be written to config.anothervalue.
  • Call config.finalizeConfig if defined for a given struct.

If value is set both by config file and command-line argument, the latter takes priority.

Config files

Currently config file is named appname.cfg and uses simple key-value format:

key = value
another key = " value that starts with a whitespace"

The following locations are checked for config file presence:

  1. Current working directory
  2. Same folder as the executable
  3. $XDG_CONFIG_HOME (Posix) or %LOCALAPPDATA% (Windows)

d-simpleconfig's People

Contributors

mihails-strasuns avatar

Watchers

James Cloos avatar Laeeth Isharc avatar

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.