diff --git a/include/blt/parse/argparse.h b/include/blt/parse/argparse.h index 7114cfc..dbdb2e6 100644 --- a/include/blt/parse/argparse.h +++ b/include/blt/parse/argparse.h @@ -91,6 +91,14 @@ namespace blt::parser { [[nodiscard]] inline std::vector& getFlags() { return flags; } + + [[nodiscard]] inline const std::vector& getNames() const { + return names; + } + + [[nodiscard]] inline const std::vector& getFlags() const { + return flags; + } }; class arg_nargs { @@ -191,6 +199,8 @@ namespace blt::parser { class argparse { private: arg_tokenizer tokenizer; + + static bool validateArgument(const arg_properties& args); public: argparse() = default; diff --git a/src/blt/parse/argparse.cpp b/src/blt/parse/argparse.cpp index 95b7c44..df7938a 100644 --- a/src/blt/parse/argparse.cpp +++ b/src/blt/parse/argparse.cpp @@ -4,6 +4,7 @@ * See LICENSE file for license detail */ #include +#include "blt/std/logging.h" namespace blt::parser { @@ -100,7 +101,17 @@ namespace blt::parser { args.emplace_back(argv[i]); } - void argparse::addArgument(const arg_properties& args) { - + 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) { + if (!validateArgument(args)) { + BLT_WARN("Argument contains both flags and positional names, this is not allowed!"); + BLT_WARN("(Discarding argument)"); + return; + } + } + + } \ No newline at end of file