make contains work with -- - or non flagged checks

v1
Brett 2023-08-11 12:10:00 -04:00
parent b04591fadb
commit f78eec792b
2 changed files with 20 additions and 7 deletions

View File

@ -287,6 +287,10 @@ namespace blt
inline bool contains(const std::string& key)
{
if (key.starts_with("--"))
return data.find(key.substr(2)) != data.end();
if (key.starts_with('-'))
return data.find(key.substr(1)) != data.end();
return data.find(key) != data.end();
}
} loaded_args;

View File

@ -70,9 +70,14 @@ int (*func_func_in)(int) = &test_as_func;
int main(int argc, const char** argv) {
blt::arg_parse parser;
parser.addArgument(blt::arg_builder({"-c", "--no-color"}).setAction(blt::arg_action_t::STORE_TRUE).build());
parser.addArgument(blt::arg_builder("--nbt").setHelp("Run NBT tests.").setAction(blt::arg_action_t::STORE_TRUE).build());
auto args = parser.parse_args(argc, argv);
for (auto& a : args)
BLT_TRACE(a.first);
BLT_TRACE(args.contains("nbt"));
if (args.contains("--no-color")) {
for (int i = (int)blt::logging::log_level::NONE; i < (int)blt::logging::log_level::FATAL; i++) {
blt::logging::setLogColor((blt::logging::log_level)i, "");
@ -228,6 +233,7 @@ int main(int argc, const char** argv) {
//
// BLT_INFO("STDDEV of # random values: %f", stdev);
if (args.contains("--nbt"))
{
std::fstream nbtFile("super_file.nbt", std::ios::out | std::ios::binary);
blt::fs::fstream_block_writer blockWriter(nbtFile);
@ -285,6 +291,8 @@ int main(int argc, const char** argv) {
nbtFile.close();
}
if (args.contains("--nbt"))
{
std::fstream nbtInputFile("super_file.nbt", std::ios::in | std::ios::binary);
blt::fs::fstream_block_reader blockReader(nbtInputFile);
blt::nbt::NBTReader nbtReader(blockReader);
@ -292,6 +300,7 @@ int main(int argc, const char** argv) {
auto shortTag = nbtReader.getTag<blt::nbt::tag_short>("shortTest");
BLT_TRACE("Got short: %d", shortTag->get());
}
return 0;
}