Minor improvements and fixes.

test/nbt_helpers: add a headline to output
Build system: remove comma from array that I added bc I thought it was correct sytax, it wasn't
lib/cli: change argument order of PositionalArgument constructor to fit in with Flag and UnpositionalArgument
lib/cli: properly define what is private and what is public in the ArgumentsParser class
BodgeMaster-unfinished
BodgeMaster 2022-07-15 08:46:53 +02:00
parent 390087fc35
commit a1223ea4b9
4 changed files with 26 additions and 21 deletions

View File

@ -72,7 +72,7 @@ echo "Building tools..."
mkdir -pv bin/tools
# add compile commands to this array
COMPILE_COMMANDS=(
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -l:nbt.so -o bin/tools/dumpnbt",
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -l:nbt.so -o bin/tools/dumpnbt"
"$CXX_WITH_FLAGS src/tools/hexnet.cpp -Ldependencies/sockpp-0.7.1/build -l:libsockpp.so -Idependencies/sockpp-0.7.1/include -o bin/tools/hexnet"
)
for command in ${!COMPILE_COMMANDS[@]}; do

View File

@ -46,7 +46,7 @@ namespace CLI {
PositionalArgument::PositionalArgument() {
this->present = false;
}
PositionalArgument::PositionalArgument(std::string description, std::string placeholder) {
PositionalArgument::PositionalArgument(std::string placeholder, std::string description) {
this->description = description;
this->placeholder = placeholder;
this->present = false;

View File

@ -58,32 +58,34 @@ namespace CLI {
std::string value;
PositionalArgument();
PositionalArgument(std::string description, std::string placeholder);
PositionalArgument(std::string placeholder, std::string description);
};
class ArgumentsParser {
bool wrongUsage;
std::vector<std::string> wrongUsageMessages;
private:
std::string programName;
std::map<char, Flag*> flagsByShortName;
std::map<std::string, Flag*> flagsByLongName;
std::map<char, UnpositionalArgument*> argumentsByShortName;
std::map<std::string, UnpositionalArgument*> argumentsByLongName;
std::vector<PositionalArgument> positionalArguments;
std::string programName;
std::map<char, Flag*> flagsByShortName;
std::map<std::string, Flag*> flagsByLongName;
std::map<char, UnpositionalArgument*> argumentsByShortName;
std::map<std::string, UnpositionalArgument*> argumentsByLongName;
std::vector<PositionalArgument> positionalArguments;
public:
bool wrongUsage;
std::vector<std::string> wrongUsageMessages;
// using int here bc that's how main() is defined
ArgumentsParser(int argc, char* argv[], std::vector<Flag> flags, std::vector<UnpositionalArgument> unpositionalArguments, std::vector<PositionalArgument> positionalArguments);
~ArgumentsParser();
// using int here bc that's how main() is defined
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<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);
std::string getUsage();
std::string getUsage();
};
}

View File

@ -23,6 +23,9 @@
#include "../lib/error.h++"
int main(){
std::cout << "################################################################################" << std::endl;
std::cout << "NBT helper tests" << std::endl;
std::cout << "################################################################################" << std::endl;
// used for all integer tests
uint8_t dataForIntTest[] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39};