From f5b0b74f94cdf32260133cb36bde65a84f9e9878 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Fri, 15 Jul 2022 09:11:39 +0200 Subject: [PATCH] lib/cli: remove useless arguments from getters, remove useless getter getProgramName (made the string public instead) --- src/lib/cli.cpp | 17 +++++------------ src/lib/cli.h++ | 13 ++++++------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/lib/cli.cpp b/src/lib/cli.cpp index c3b001c..a09b4c1 100644 --- a/src/lib/cli.cpp +++ b/src/lib/cli.cpp @@ -190,14 +190,7 @@ namespace CLI { } } - ErrorOr ArgumentsParser::getProgramName() { - if (this->wrongUsage) { - return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->programName); - } - return ErrorOr(this->programName); - } - - ErrorOr ArgumentsParser::getFlag(int argc, char* argv[], char shortName) { + ErrorOr ArgumentsParser::getFlag(char shortName) { if (!this->flagsByShortName.contains(shortName)) return ErrorOr(true, ErrorCodes::UNKNOWN_KEY, false); if (this->wrongUsage) { return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->flagsByShortName[shortName]->present); @@ -205,7 +198,7 @@ namespace CLI { return ErrorOr(this->flagsByShortName[shortName]->present); } - ErrorOr ArgumentsParser::getFlag(int argc, char* argv[], std::string longName) { + ErrorOr ArgumentsParser::getFlag(std::string longName) { if (!this->flagsByLongName.contains(longName)) return ErrorOr(true, ErrorCodes::UNKNOWN_KEY, false); if (this->wrongUsage) { return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->flagsByLongName[longName]->present); @@ -213,7 +206,7 @@ namespace CLI { return ErrorOr(this->flagsByLongName[longName]->present); } - ErrorOr ArgumentsParser::getPositionalArgument(int argc, char* argv[], std::vector::size_type position){ + ErrorOr ArgumentsParser::getPositionalArgument(std::vector::size_type position){ if (position >= this->positionalArguments.size()) return ErrorOr(true, ErrorCodes::OUT_OF_RANGE, std::string("")); if (this->wrongUsage) { if (this->positionalArguments.at(position).present) return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->positionalArguments.at(position).value); @@ -222,7 +215,7 @@ namespace CLI { return ErrorOr(this->positionalArguments.at(position).value); } - ErrorOr ArgumentsParser::getUnpositionalArgument(int argc, char* argv[], char shortName) { + ErrorOr ArgumentsParser::getUnpositionalArgument(char shortName) { if (!this->argumentsByShortName.contains(shortName)) return ErrorOr(true, ErrorCodes::UNKNOWN_KEY, std::string("")); if (this-wrongUsage) { if (this->argumentsByShortName[shortName]->present) return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->argumentsByShortName[shortName]->value); @@ -233,7 +226,7 @@ namespace CLI { else return ErrorOr(false, ErrorCodes::NOT_PRESENT, std::string("")); } - ErrorOr ArgumentsParser::getUnpositionalArgument(int argc, char* argv[], std::string longName) { + ErrorOr ArgumentsParser::getUnpositionalArgument(std::string longName) { if (!this->argumentsByLongName.contains(longName)) return ErrorOr(true, ErrorCodes::UNKNOWN_KEY, std::string("")); if (this-wrongUsage) { if (this->argumentsByLongName[longName]->present) return ErrorOr(true, ErrorCodes::WRONG_USAGE, this->argumentsByLongName[longName]->value); diff --git a/src/lib/cli.h++ b/src/lib/cli.h++ index 7dc5ff1..9307483 100644 --- a/src/lib/cli.h++ +++ b/src/lib/cli.h++ @@ -63,7 +63,6 @@ namespace CLI { class ArgumentsParser { private: - std::string programName; std::map flagsByShortName; std::map flagsByLongName; std::map argumentsByShortName; @@ -71,6 +70,7 @@ namespace CLI { std::vector positionalArguments; public: + std::string programName; bool wrongUsage; std::vector wrongUsageMessages; @@ -78,12 +78,11 @@ namespace CLI { ArgumentsParser(int argc, char* argv[], std::vector flags, std::vector unpositionalArguments, std::vector positionalArguments); ~ArgumentsParser(); - ErrorOr getProgramName(); - ErrorOr getFlag(int argc, char* argv[], char shortName); - ErrorOr getFlag(int argc, char* argv[], std::string longName); - ErrorOr getPositionalArgument(int argc, char* argv[], std::vector::size_type position); - ErrorOr getUnpositionalArgument(int argc, char* argv[], char shortName); - ErrorOr getUnpositionalArgument(int argc, char* argv[], std::string longName); + ErrorOr getFlag(char shortName); + ErrorOr getFlag(std::string longName); + ErrorOr getPositionalArgument(std::vector::size_type position); + ErrorOr getUnpositionalArgument(char shortName); + ErrorOr getUnpositionalArgument(std::string longName); std::string getUsage(); };