1 module vars; 2 import commands.uda; 3 import std.stdio; 4 5 class VarStore { 6 private { 7 string[string] variables; 8 } 9 10 @CommandNamespace("var"): 11 @Command("get", "Get a variable from the temporary store", 1, 1) 12 string getVar(string[] args) { 13 string varName = args[0]; 14 if (auto var = varName in variables) { 15 writeln(varName, ": ", *var); 16 return *var; 17 } 18 else { 19 throw new Exception("Could not find var ", varName); 20 } 21 } 22 23 @Command("set", "Set a variable in the temporary store", 2, 2) 24 string setVar(string[] args) { 25 string varName = args[0]; 26 string varVal = args[1]; 27 variables[varName] = varVal; 28 return varVal; 29 } 30 } 31 32 mixin RegisterModule!VarStore;