pgator

Config reading system.

Ctor AppConfig(string) create a  config from file.

License
Subject to the terms of the MIT license, as written in the included LICENSE file.
Authors
Zaramzan

struct  AppConfig;

Represent configuration file.

Authors
Zaramzan

this(Json json);

Deserializing config from provided json object.

Throws
InvalidConfig if json is incorrect (without info about config file name)
Authors
Zaramzan NCrashed

immutable this(string path);

Parsing config from file path.

Throws
InvalidConfig
Authors
Zaramzan NCrashed

struct  SqlConfig;

Describes basic sql info in AppConfig


class  InvalidConfig: object.Exception;

The exception is thrown when configuration parsing error occurs (AppConfig constructor). Also encapsulates config file name.

Throws
 InvalidConfig
Authors
Zaramzan NCrashed

class  NoConfigLoaded: object.Exception;

The exception is thrown by tryConfigPaths is called and all config file alternatives are failed to be loaded.

Also encapsulates a set of tried paths.

Authors
NCrashed

alias  LoadedConfig = std.typecons.Tuple!(immutable(AppConfig), "config", string, "path").Tuple;

Return value from tryConfigPaths. Handles loaded config and exact file path.

Authors
NCrashed

LoadedConfig  tryConfigPaths(R)(R paths) if (isInputRange!R && is(ElementType!R == string));

Takes range of paths and one at a time tries to load config from each one. If the path doesn't exist, then the next candidate is checked. If the file exists, but parsing or deserializing are failed, InvalidConfig exception is thrown.

If functions go out of paths and none of them can be opened, then NoConfigLoaded exception is thrown.

Throws
NoConfigLoaded if can't load configuration file. InvalidConfig if configuration file is invalid (first successfully opened)
Authors
NCrashed Zaramzan

AppConfig  defaultConfig();

Returns config example to be edited by end user.

This configuration is generated only if explicit key is passed to the application.

Authors
NCrashed

bool  writeConfig(AppConfig appConfig, string name);

Writes configuration appConfig to file path name. It is a wrapper function around writeJson.

Authors
NCrashed Zaramzan

bool  writeJson(Json json, string name);

Writes down json to provided file name.

Authors
NCrashed Zaramzan

void  genConfig(string path);

Generates and write down minimal configuration to path.

Authors
NCrashed Zaramzan