1 module jcli.core.udas; 2 3 import jcli.core.pattern; 4 5 package(jcli) mixin template BeingNamed() 6 { 7 Pattern pattern; 8 string description; 9 10 string name() const @nogc nothrow pure @safe { return pattern[0]; } 11 } 12 13 // NOTE: 14 // The constructors seem to not work when mixed in with the template above, 15 // which is why I mix in the string. 16 private enum string constructorsMixinString = 17 q{ 18 this(string stringPattern, string description = "") pure 19 { 20 this.pattern = Pattern.parse(stringPattern); 21 this.description = description; 22 } 23 24 this(Pattern pattern, string description = "") pure nothrow @nogc 25 { 26 this.pattern = pattern; 27 this.description = description; 28 } 29 30 this(string[] pattern, string description = "") pure 31 { 32 this.pattern = Pattern(pattern); 33 this.description = description; 34 } 35 36 // I want this constructor to exit, but its kind of weird to do rn. 37 // this(string description) pure nothrow @nogc 38 // { 39 // this.pattern = Pattern.init; 40 // this.description = description; 41 // } 42 }; 43 44 struct Command 45 { 46 mixin BeingNamed; 47 mixin(constructorsMixinString); 48 } 49 50 struct CommandDefault 51 { 52 string description; 53 } 54 55 struct ArgPositional 56 { 57 string name; 58 string description; 59 60 @nogc nothrow pure @safe: 61 62 this(string description) 63 { 64 this.description = description; 65 this.name = ""; 66 } 67 68 this(string name, string description) 69 { 70 this.description = description; 71 this.name = name; 72 } 73 } 74 75 struct ArgNamed 76 { 77 mixin BeingNamed; 78 mixin(constructorsMixinString); 79 } 80 81 struct ArgGroup 82 { 83 string name; 84 string description = ""; 85 } 86 87 enum ArgOverflow; 88 enum ArgRaw; 89 90 /// Mark the member pointers of the command context struct 91 /// to the parent command context struct with this. 92 /// That will make it join the command group. 93 /// The `onExecute` method will be called after the `onExecute` of that parent executes. 94 /// 95 /// For now, when multiple such fields exist, the command will be a child of both, 96 /// and when the command is resolved, only the context pointer of 97 /// the parent command that it was resolved through will be not-null. 98 enum ParentCommand; 99 100 struct Subcommands(SubcommandTypes...) 101 { 102 alias Types = SubcommandTypes; 103 }