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() {
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 {
@ -191,6 +199,8 @@ namespace blt::parser {
class argparse {
private:
arg_tokenizer tokenizer;
static bool validateArgument(const arg_properties& args);
public:
argparse() = default;

View File

@ -4,6 +4,7 @@
* See LICENSE file for license detail
*/
#include <blt/parse/argparse.h>
#include "blt/std/logging.h"
namespace blt::parser {
@ -100,7 +101,17 @@ namespace blt::parser {
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) {
if (!validateArgument(args)) {
BLT_WARN("Argument contains both flags and positional names, this is not allowed!");
BLT_WARN("(Discarding argument)");
return;
}
}
}
}