lib/cli: remove useless arguments from getters, remove useless getter getProgramName (made the string public instead)

BodgeMaster-unfinished
BodgeMaster 2022-07-15 09:11:39 +02:00
parent a1223ea4b9
commit f5b0b74f94
2 changed files with 11 additions and 19 deletions

View File

@ -190,14 +190,7 @@ namespace CLI {
}
}
ErrorOr<std::string> ArgumentsParser::getProgramName() {
if (this->wrongUsage) {
return ErrorOr<std::string>(true, ErrorCodes::WRONG_USAGE, this->programName);
}
return ErrorOr<std::string>(this->programName);
}
ErrorOr<bool> ArgumentsParser::getFlag(int argc, char* argv[], char shortName) {
ErrorOr<bool> ArgumentsParser::getFlag(char shortName) {
if (!this->flagsByShortName.contains(shortName)) return ErrorOr<bool>(true, ErrorCodes::UNKNOWN_KEY, false);
if (this->wrongUsage) {
return ErrorOr<bool>(true, ErrorCodes::WRONG_USAGE, this->flagsByShortName[shortName]->present);
@ -205,7 +198,7 @@ namespace CLI {
return ErrorOr<bool>(this->flagsByShortName[shortName]->present);
}
ErrorOr<bool> ArgumentsParser::getFlag(int argc, char* argv[], std::string longName) {
ErrorOr<bool> ArgumentsParser::getFlag(std::string longName) {
if (!this->flagsByLongName.contains(longName)) return ErrorOr<bool>(true, ErrorCodes::UNKNOWN_KEY, false);
if (this->wrongUsage) {
return ErrorOr<bool>(true, ErrorCodes::WRONG_USAGE, this->flagsByLongName[longName]->present);
@ -213,7 +206,7 @@ namespace CLI {
return ErrorOr<bool>(this->flagsByLongName[longName]->present);
}
ErrorOr<std::string> ArgumentsParser::getPositionalArgument(int argc, char* argv[], std::vector<CLI::PositionalArgument>::size_type position){
ErrorOr<std::string> ArgumentsParser::getPositionalArgument(std::vector<CLI::PositionalArgument>::size_type position){
if (position >= this->positionalArguments.size()) return ErrorOr<std::string>(true, ErrorCodes::OUT_OF_RANGE, std::string(""));
if (this->wrongUsage) {
if (this->positionalArguments.at(position).present) return ErrorOr<std::string>(true, ErrorCodes::WRONG_USAGE, this->positionalArguments.at(position).value);
@ -222,7 +215,7 @@ namespace CLI {
return ErrorOr<std::string>(this->positionalArguments.at(position).value);
}
ErrorOr<std::string> ArgumentsParser::getUnpositionalArgument(int argc, char* argv[], char shortName) {
ErrorOr<std::string> ArgumentsParser::getUnpositionalArgument(char shortName) {
if (!this->argumentsByShortName.contains(shortName)) return ErrorOr<std::string>(true, ErrorCodes::UNKNOWN_KEY, std::string(""));
if (this-wrongUsage) {
if (this->argumentsByShortName[shortName]->present) return ErrorOr<std::string>(true, ErrorCodes::WRONG_USAGE, this->argumentsByShortName[shortName]->value);
@ -233,7 +226,7 @@ namespace CLI {
else return ErrorOr<std::string>(false, ErrorCodes::NOT_PRESENT, std::string(""));
}
ErrorOr<std::string> ArgumentsParser::getUnpositionalArgument(int argc, char* argv[], std::string longName) {
ErrorOr<std::string> ArgumentsParser::getUnpositionalArgument(std::string longName) {
if (!this->argumentsByLongName.contains(longName)) return ErrorOr<std::string>(true, ErrorCodes::UNKNOWN_KEY, std::string(""));
if (this-wrongUsage) {
if (this->argumentsByLongName[longName]->present) return ErrorOr<std::string>(true, ErrorCodes::WRONG_USAGE, this->argumentsByLongName[longName]->value);

View File

@ -63,7 +63,6 @@ namespace CLI {
class ArgumentsParser {
private:
std::string programName;
std::map<char, Flag*> flagsByShortName;
std::map<std::string, Flag*> flagsByLongName;
std::map<char, UnpositionalArgument*> argumentsByShortName;
@ -71,6 +70,7 @@ namespace CLI {
std::vector<PositionalArgument> positionalArguments;
public:
std::string programName;
bool wrongUsage;
std::vector<std::string> wrongUsageMessages;
@ -78,12 +78,11 @@ namespace CLI {
ArgumentsParser(int argc, char* argv[], std::vector<Flag> flags, std::vector<UnpositionalArgument> unpositionalArguments, std::vector<PositionalArgument> positionalArguments);
~ArgumentsParser();
ErrorOr<std::string> getProgramName();
ErrorOr<bool> getFlag(int argc, char* argv[], char shortName);
ErrorOr<bool> getFlag(int argc, char* argv[], std::string longName);
ErrorOr<std::string> getPositionalArgument(int argc, char* argv[], std::vector<CLI::PositionalArgument>::size_type position);
ErrorOr<std::string> getUnpositionalArgument(int argc, char* argv[], char shortName);
ErrorOr<std::string> getUnpositionalArgument(int argc, char* argv[], std::string longName);
ErrorOr<bool> getFlag(char shortName);
ErrorOr<bool> getFlag(std::string longName);
ErrorOr<std::string> getPositionalArgument(std::vector<CLI::PositionalArgument>::size_type position);
ErrorOr<std::string> getUnpositionalArgument(char shortName);
ErrorOr<std::string> getUnpositionalArgument(std::string longName);
std::string getUsage();
};