/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: CmdLine.cpp Date: 2022-1-31 Author: Reece ***/ #include #include "CmdLine.hpp" #include "CmdLinePlatform.hpp" namespace Aurora::CmdLine { static const AuString kEmptyString; static AuList gCmdFlags; static AuList gCmdValues; static AuHashMap gCmdValueMap; static AuHashMap gCmdFlagLookup; static AuList gCmdLineString; AUKN_SYM const AuList &GetCommandLineArguments() { return gCmdLineString; } AUKN_SYM bool HasFlag(const AuString &key) { return gCmdFlagLookup.find(key) != gCmdFlagLookup.end(); } AUKN_SYM bool HasValue(const AuString &key) { return gCmdValueMap.find(key) != gCmdValueMap.end(); } AUKN_SYM const AuString &GetValue(const AuString &key, const AuString &defaultValue) { auto itr = gCmdValueMap.find(key); if (itr == gCmdValueMap.end()) return defaultValue; return itr->second; } AUKN_SYM const AuString &GetValue(const AuString &key) { return GetValue(key, kEmptyString); } AUKN_SYM const AuList &GetFlags() { return gCmdFlags; } AUKN_SYM const AuList &GetValues() { return gCmdValues; } static void ProcessArgs() { for (const auto &arg : gCmdLineString) { auto valueAssignment = arg.find('='); if (valueAssignment == arg.npos) { gCmdFlags.push_back(arg); gCmdFlagLookup[arg] = true; } else { auto key = arg.substr(0, valueAssignment); auto val = arg.substr(valueAssignment + 1); gCmdValues.push_back(key); gCmdValueMap[key] = val; } } } void Init() { gCmdLineString = GetCmdString(); if (gCmdLineString.size()) { gCmdLineString.erase(gCmdLineString.begin()); } ProcessArgs(); } }