88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
|
/***
|
||
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||
|
|
||
|
File: CmdLine.cpp
|
||
|
Date: 2022-1-31
|
||
|
Author: Reece
|
||
|
***/
|
||
|
#include <Source/RuntimeInternal.hpp>
|
||
|
#include "CmdLine.hpp"
|
||
|
#include "CmdLinePlatform.hpp"
|
||
|
|
||
|
namespace Aurora::CmdLine
|
||
|
{
|
||
|
static const AuString kEmptyString;
|
||
|
static AuList<AuString> gCmdFlags;
|
||
|
static AuList<AuString> gCmdValues;
|
||
|
static AuHashMap<AuString, AuString> gCmdValueMap;
|
||
|
static AuHashMap<AuString, bool> gCmdFlagLookup;
|
||
|
static AuList<AuString> gCmdLineString;
|
||
|
|
||
|
AUKN_SYM const AuList<AuString> &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<AuString> &GetFlags()
|
||
|
{
|
||
|
return gCmdFlags;
|
||
|
}
|
||
|
|
||
|
AUKN_SYM const AuList<AuString> &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();
|
||
|
}
|
||
|
}
|