Coding your own main function
Almost all sample applications used a static this()
constructor for initialization. The main()
function provided by vibe.d is used if the VibeDefaultMain
version is set in the dub.sdl
file. Basically, the main()
function contains the following code:
int main() { import vibe.core.args : finalizeCommandLineOptions; import vibe.core.core : runEventLoop, lowerPrivileges; if (!finalizeCommandLineOptions()) return 0; lowerPrivileges(); return runEventLoop(); }
First, the parsing of the command-line options is finalized. Then privileges are dropped if requested and the event loop is started.
Your code can retrieve the value of options, too. The readOption()
and readRequiredOption()
functions return the value of an option. These functions differ in that the latter function enforces that the option exists, throwing an exception if it does not exist. Options can be specified on the command line and also in the vibe.conf
configuration file. On a Unix system, the...