6std::unordered_map<std::string, std::string> CommandLine::s_values;
7std::unordered_set<std::string> CommandLine::s_flags;
8void(*CommandLine::s_helpCallback)(
const char* exe) =
nullptr;
11 s_helpCallback = callback;
18 for (
int i = 1; i < argc; ++i) {
19 std::string a = argv[i];
20 if (a.empty())
continue;
22 if (a ==
"help" || a ==
"--help" || a ==
"-help") {
23 if (s_helpCallback) s_helpCallback(argv[0]);
27 if (a.size() >= 2 && a[0] ==
'-' && a[1] ==
'-') {
30 }
else if (a[0] ==
'-') {
33 if (i + 1 < argc && argv[i + 1][0] !=
'-') {
34 s_values[a] = argv[++i];
44 const std::string& defaultVal) {
45 auto it = s_values.find(flag);
46 return (it != s_values.end()) ? it->second : defaultVal;
50 return s_flags.count(flag) > 0;
static std::string GetValue(const std::string &flag, const std::string &defaultVal="")
Returns the raw string value stored for -flag, or defaultVal if it was not passed.
static void SetHelpCallback(void(*callback)(const char *exe))
static bool HasFlag(const std::string &flag)
True if --flag was present on the command line.
static void Parse(int argc, char **argv)
Parses argv into the value/flag tables. Call once from main(), before Application.
Root namespace for everything the engine exposes.