1 /** 2 License: 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 Authors: 28 aermicioi 29 **/ 30 module aermicioi.aedi_property_reader.env.env_container; 31 32 import aermicioi.aedi; 33 import aermicioi.aedi_property_reader.env.env_factory; 34 import aermicioi.aedi_property_reader.generic_convertor_container; 35 import std.process; 36 import std.range; 37 import std.typecons; 38 39 /** 40 Environment variables data source/locator used by converting containers. 41 **/ 42 class EnvironmentLocator : Locator!(string, string) { 43 44 public { 45 46 /** 47 Get an environment variable from environment. 48 49 Params: 50 path = the element id. 51 52 Throws: 53 NotFoundException in case if the element wasn't found. 54 55 Returns: 56 string element if it is available. 57 **/ 58 string get(string path) { 59 auto env = environment.get(path); 60 61 if (env is null) { 62 throw new NotFoundException("Could not find environment variable identified by " ~ path); 63 } 64 65 return env; 66 } 67 68 /** 69 Check if environment variable is set. 70 71 Params: 72 path = identity of element. 73 74 Returns: 75 bool true if an element by key is present in Locator. 76 **/ 77 bool has(in string path) inout { 78 return environment.get(path) !is null; 79 } 80 } 81 } 82 83 /** 84 Generic convertor container version for environment variables. 85 **/ 86 alias EnvironmentConvertorContainer = GenericConvertorContainer!(string, StringConvertorFactory);