1 module clid.util; 2 3 import std.traits : hasUDA, getUDAs; 4 5 import clid.attributes; 6 import clid.validate; 7 8 /** 9 * Checks if a given struct is a valid configuration struct. 10 */ 11 void validateStruct(C)() 12 { 13 static assert(is(C == struct), "Configuration object must be a struct"); 14 static foreach (member; __traits(allMembers, C)) 15 { 16 static if (!hasUDAV!(C, member, Parameter)) 17 { 18 static assert(!hasUDAV!(C, member, Description), 19 "Cannot have @Description without @Parameter in command line argument struct."); 20 static assert(!hasUDAV!(C, member, Validate), 21 "Cannot have @Validate without @Parameter in command line argument struct."); 22 } 23 } 24 } 25 26 /** 27 * Wrapper around __traits(getMember, ...) 28 */ 29 template Value(C, alias m) 30 { 31 alias Value = __traits(getMember, C, m); 32 } 33 34 /** 35 * Wrapper around __traits(getMember, ...) 36 */ 37 template Value(alias c, alias m) 38 { 39 alias Value = __traits(getMember, c, m); 40 } 41 42 /** 43 * Wrapper around hasUDA!(...) 44 */ 45 template hasUDAV(C, alias m, T) 46 { 47 alias hasUDAV = hasUDA!(Value!(C, m), T); 48 } 49 50 /** 51 * Wrapper around hasUDA!(...) 52 */ 53 template hasUDAV(C, alias m, alias t) 54 { 55 alias hasUDAV = hasUDA!(Value!(C, m), t); 56 } 57 58 /** 59 * Wrapper around hasUDA!(...) 60 */ 61 template hasUDAV(alias c, alias m, alias t) 62 { 63 alias hasUDAV = hasUDA!(Value!(c, m), t); 64 }