Brett 2023-07-29 14:04:46 -04:00
parent db5c7fe37f
commit 0febd6e8aa
2 changed files with 23 additions and 2 deletions

View File

@ -91,6 +91,14 @@ namespace blt::parser {
[[nodiscard]] inline std::vector<std::string>& getFlags() { [[nodiscard]] inline std::vector<std::string>& getFlags() {
return flags; return flags;
} }
[[nodiscard]] inline const std::vector<std::string>& getNames() const {
return names;
}
[[nodiscard]] inline const std::vector<std::string>& getFlags() const {
return flags;
}
}; };
class arg_nargs { class arg_nargs {
@ -191,6 +199,8 @@ namespace blt::parser {
class argparse { class argparse {
private: private:
arg_tokenizer tokenizer; arg_tokenizer tokenizer;
static bool validateArgument(const arg_properties& args);
public: public:
argparse() = default; argparse() = default;

View File

@ -4,6 +4,7 @@
* See LICENSE file for license detail * See LICENSE file for license detail
*/ */
#include <blt/parse/argparse.h> #include <blt/parse/argparse.h>
#include "blt/std/logging.h"
namespace blt::parser { namespace blt::parser {
@ -100,7 +101,17 @@ namespace blt::parser {
args.emplace_back(argv[i]); args.emplace_back(argv[i]);
} }
bool argparse::validateArgument(const arg_properties& args) {
return !args.a_flags.getFlags().empty() ^ !args.a_flags.getNames().empty();
}
void argparse::addArgument(const arg_properties& args) { void argparse::addArgument(const arg_properties& args) {
if (!validateArgument(args)) {
BLT_WARN("Argument contains both flags and positional names, this is not allowed!");
BLT_WARN("(Discarding argument)");
return;
}
}
} }
}