simpleconfig ~mihails-strasuns-patch-1

Simple utility to combine CLI args and config file into single config


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

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)

Authors:
  • Mihails Strasuns
Dependencies:
none
Versions:
1.0.0 2021-Mar-06
0.3.0 2019-Jun-09
0.2.1 2019-Feb-01
0.2.0 2019-Jan-03
0.1.0 2018-Dec-27
Show all 9 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 221 downloads total

Score:
1.1
Short URL:
simpleconfig.dub.pm