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) 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(); return data.find(key) != data.end();
} }
} loaded_args; } loaded_args;

View File

@ -70,9 +70,14 @@ int (*func_func_in)(int) = &test_as_func;
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
blt::arg_parse parser; 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({"-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); 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")) { if (args.contains("--no-color")) {
for (int i = (int)blt::logging::log_level::NONE; i < (int)blt::logging::log_level::FATAL; i++) { 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, ""); 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); // BLT_INFO("STDDEV of # random values: %f", stdev);
if (args.contains("--nbt"))
{ {
std::fstream nbtFile("super_file.nbt", std::ios::out | std::ios::binary); std::fstream nbtFile("super_file.nbt", std::ios::out | std::ios::binary);
blt::fs::fstream_block_writer blockWriter(nbtFile); blt::fs::fstream_block_writer blockWriter(nbtFile);
@ -285,13 +291,16 @@ int main(int argc, const char** argv) {
nbtFile.close(); nbtFile.close();
} }
std::fstream nbtInputFile("super_file.nbt", std::ios::in | std::ios::binary); if (args.contains("--nbt"))
blt::fs::fstream_block_reader blockReader(nbtInputFile); {
blt::nbt::NBTReader nbtReader(blockReader); std::fstream nbtInputFile("super_file.nbt", std::ios::in | std::ios::binary);
nbtReader.read(); blt::fs::fstream_block_reader blockReader(nbtInputFile);
blt::nbt::NBTReader nbtReader(blockReader);
nbtReader.read();
auto shortTag = nbtReader.getTag<blt::nbt::tag_short>("shortTest"); auto shortTag = nbtReader.getTag<blt::nbt::tag_short>("shortTest");
BLT_TRACE("Got short: %d", shortTag->get()); BLT_TRACE("Got short: %d", shortTag->get());
}
return 0; return 0;
} }