1 module jcli.introspect.data;
2 
3 import jcli.core, std;
4 
5 enum ArgExistence
6 {
7     mandatory   = 0,
8     optional    = 1 << 0,
9     multiple    = 1 << 1
10 }
11 
12 enum ArgParseScheme
13 {
14     normal,
15     bool_,
16     repeatableName
17 }
18 
19 enum ArgAction
20 {
21     normal,
22     count
23 }
24 
25 enum ArgConfig
26 {
27     none,
28     canRedefine = 1 << 0,
29     caseInsensitive = 1 << 1
30 }
31 
32 struct CommandInfo(alias CommandT_)
33 {
34     alias CommandT = CommandT_;
35 
36     Pattern pattern;
37     string  description;
38     bool    isDefault;
39 
40     ArgIntrospect!(ArgPositional, CommandT)[]   positionalArgs;
41     ArgIntrospect!(ArgNamed, CommandT)[]        namedArgs;
42     ArgIntrospect!(ArgRaw, CommandT)            rawArg;
43     ArgIntrospect!(ArgOverflow, CommandT)       overflowArg;
44 }
45 
46 struct ArgIntrospect(alias UDA_, alias CommandT_)
47 {
48     alias UDA = UDA_;
49     alias CommandT = CommandT_;
50 
51     string identifier;
52     UDA uda;
53     ArgExistence existence;
54     ArgParseScheme scheme;
55     ArgAction action;
56     ArgConfig config;
57     ArgGroup group;
58 }
59 
60 template getArgSymbol(alias ArgIntrospectT)
61 {
62     mixin("alias getArgSymbol = ArgIntrospectT.CommandT."~ArgIntrospectT.identifier~";");
63 }
64 
65 ref auto getArg(alias ArgIntrospectT)(ref return ArgIntrospectT.CommandT command)
66 {
67     mixin("return command."~ArgIntrospectT.identifier~";");
68 }
69 ///
70 unittest
71 {
72     import jcli.introspect.gather;
73 
74     @CommandDefault()
75     static struct T
76     {
77         @ArgPositional
78         int a;
79     }
80 
81     T t = T(360);
82     enum Info = commandInfoFor!T();
83     assert(getArg!(Info.positionalArgs[0])(t) == 360);
84     
85     static assert(__traits(identifier, getArgSymbol!(Info.positionalArgs[0])) == "a");
86 }