Creating a command-line function caller
One useful application of reflection is that it builds dynamic interfaces automatically. Reflection can be used to help the code that interacts with a scripting language, a network protocol, and more. Here, we'll write a command-line program that calls functions and displays information about them when help is requested. We'll need to be able to add new functions without needing any boilerplate code to be added along with it.
How to do it…
We can create a command-line function caller by performing the following steps:
Loop over all members of the module.
Find functions with a protection level of export (alternatively, you may look for the presence of a user-defined attribute).
If the user requested help, list the possible functions or details about a particular function, by performing the following steps:
Use a user-defined attribute for documentation.
Use
std.traits' Parameter*Tuple
family of functions to get details about the function.
If the user wants...