From 69f15e928af2fb334ae5e7ce5043404c0823438d Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Tue, 2 Aug 2022 02:03:50 +0200 Subject: [PATCH] lib/cli: Add fields for a short description and additional usage information to the arguments parser This is in preparation for building the help text generator. --- src/lib/cli.cpp | 9 +++++++++ src/lib/cli.h++ | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/lib/cli.cpp b/src/lib/cli.cpp index 8ec37c9..fd10870 100644 --- a/src/lib/cli.cpp +++ b/src/lib/cli.cpp @@ -189,6 +189,15 @@ namespace CLI { } } + ArgumentsParser::ArgumentsParser(int argc, const char* const argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments, std::string description): ArgumentsParser::ArgumentsParser(argc, argv, flags, unpositionalArguments, positionalArguments) { + this->description = description; + } + + ArgumentsParser::ArgumentsParser(int argc, const char* const argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments, std::string description, std::string additionalInfo): ArgumentsParser::ArgumentsParser(argc, argv, flags, unpositionalArguments, positionalArguments) { + this->description = description; + this->additionalInfo = additionalInfo; + } + ArgumentsParser::~ArgumentsParser() { //TODO: check that this actually runs for (auto const& [shortName, flag]: this->flagsByShortName) { diff --git a/src/lib/cli.h++ b/src/lib/cli.h++ index 513a03e..c306edc 100644 --- a/src/lib/cli.h++ +++ b/src/lib/cli.h++ @@ -68,6 +68,8 @@ namespace CLI { std::map argumentsByShortName; std::map argumentsByLongName; std::vector positionalArguments; + std::string description; + std::string additionalInfo; public: std::string programName; @@ -76,6 +78,8 @@ namespace CLI { // using int here bc that's how main() is defined ArgumentsParser(int argc, const char* const argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments); + ArgumentsParser(int argc, const char* const argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments, std::string description); + ArgumentsParser(int argc, const char* const argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments, std::string description, std::string additionalInfo); ~ArgumentsParser(); ErrorOr getFlag(char shortName);