diff options
author | Ralph Amissah <ralph@amissah.com> | 2017-01-29 11:57:41 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2019-04-10 15:14:14 -0400 |
commit | c8c141d8abf715c9a697d2e3dd949d4621cfea7b (patch) | |
tree | 7124b76ac74734dbe9265151a874822c70eef12f /src/sdp/ao_read_config_files.d | |
parent | defaults org, reorganize (diff) |
0.12.1 abstraction template
Diffstat (limited to 'src/sdp/ao_read_config_files.d')
-rw-r--r-- | src/sdp/ao_read_config_files.d | 160 |
1 files changed, 97 insertions, 63 deletions
diff --git a/src/sdp/ao_read_config_files.d b/src/sdp/ao_read_config_files.d index 6308df2..2e1bca6 100644 --- a/src/sdp/ao_read_config_files.d +++ b/src/sdp/ao_read_config_files.d @@ -3,88 +3,122 @@ - read config files<BR> ao_config_files.d +/ -template SiSUconfigIn() { +template ConfigIn() { private import + std.algorithm, + std.array, + std.container, std.exception, std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, std.utf, std.conv : to; - private - struct ConfigIn { - private import std.file; - final private string readInConfigFile(string conf_sdl) { - string dot_pwd = chainPath(to!string(environment["PWD"]), ".sisu").array; - string underscore_pwd = chainPath(to!string(environment["PWD"]), "_sisu").array; - string dot_home = chainPath(to!string(environment["HOME"]), ".sisu").array; - string[] possible_config_path_locations = [ - dot_pwd, - underscore_pwd, - dot_home, - "/etc/sisu" - ]; - string config_file_str; - foreach(pth; possible_config_path_locations) { - auto conf_file = format( - "%s/%s", - pth, - conf_sdl, - ); - try { - if (exists(conf_file)) { - debug(configfile) { - writeln(conf_file); - } - config_file_str = readText(conf_file); - break; + import std.file; + final string ConfigIn(C,E)(C conf_sdl, E env) { + string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; + string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; + string dot_home = chainPath(to!string(env["home"]), ".sisu").array; + string[] possible_config_path_locations = [ + dot_pwd, + underscore_pwd, + dot_home, + "/etc/sisu" + ]; + string config_file_str; + foreach(pth; possible_config_path_locations) { + auto conf_file = format( + "%s/%s", + pth, + conf_sdl, + ); + try { + if (exists(conf_file)) { + debug(configfile) { + writeln(conf_file); } - } - catch (ErrnoException ex) { - } - catch (FileException ex) { + config_file_str = readText(conf_file); + break; } } - return config_file_str; + catch (ErrnoException ex) { + } + catch (FileException ex) { + } } + return config_file_str; } } /+ +/ -template SiSUconfigSDLang() { - struct ConfigSDLangRootTag { - private auto configSDLangRootTag(string configuration, string conf_sdl_filename) { - Tag sdl_root_conf; - try { - sdl_root_conf = parseSource(configuration); - } - catch(ParseException e) { - stderr.writeln("SDLang problem with content for ", conf_sdl_filename); - stderr.writeln(e.msg); - } - debug(sdlang) { - Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; - assert(output_dir_structure_by.type == typeid(string)); - writeln(output_dir_structure_by); - writeln("conf SDL:"); - writeln(sdl_root_conf.toSDLDocument()); - } - return sdl_root_conf; +template ConfigSDLang() { + import sdlang; + private import + std.algorithm, + std.array, + std.container, + std.exception, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; + auto ConfigSDLang(string configuration, string conf_sdl_filename) { + Tag sdl_root_conf; + try { + sdl_root_conf = parseSource(configuration); } + catch(ParseException e) { + stderr.writeln("SDLang problem with content for ", conf_sdl_filename); + stderr.writeln(e.msg); + } + debug(sdlang) { + Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; + assert(output_dir_structure_by.type == typeid(string)); + writeln(output_dir_structure_by); + writeln("conf SDL:"); + writeln(sdl_root_conf.toSDLDocument()); + } + return sdl_root_conf; } } /+ +/ -template SiSUconfigSDLangHub() { - mixin SiSUconfigIn; - mixin SiSUconfigSDLang; - struct ConfigHub { - final private auto configSDLang(string conf_sdl) { - auto conf_get = ConfigIn(); - auto configuration = conf_get.readInConfigFile(conf_sdl); - auto conf = ConfigSDLangRootTag(); - auto sdl_root = conf.configSDLangRootTag(configuration, conf_sdl); - return sdl_root; - } +template ConfigHub() { + private import + std.algorithm, + std.array, + std.container, + std.exception, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; + + final auto ConfigHub(C,E)(C conf_sdl, E env) { + auto configuration = ConfigIn!()(conf_sdl, env); + auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); + return sdl_root; } } |