Here is a list of what you'll find in this README.md :
To compile the library, use setup.sh by doing in your terminal :
./setup.shOr you can do it by yourself by typing in your terminal :
[[ ! -d lib ]] && mkdir lib
g++ -c ./cpparser.cpp
ar cr libcpparser.a *.o
mv libcpparser.a lib/To compile your program you will need to add some flags, just like this :
# for more informations type './compile.sh -h'
./compile.sh <your_file> [OTHER FLAGS]
OR
You can use make if you feel like editing the source filename in the Makefile
⚠️ If you want to compile manually your program you must add some things ! Otherwise you won't be able to compile your program.
Here's an example with g++ compiler:
g++ <your_file> cpparser.cpp -IincludeEach argument type has an example in example section
There are 4 argument types (Default means the value when the argument is not called) :
Parser::STORE_ONE_VALUE:- Accessible by:
args["<argname>"].Stringorargs["<argname>"](C++ will try to convert it to a string) - Type:
std::string - Default to:
""
- Accessible by:
Parser::STORE_MULTIPLE_VALUES- Accessible by:
args["<argname>"].Vector - Type:
std::vector<std::string> - Default to:
{}
- Accessible by:
Parser::STORE_TRUE- Accessible by:
args["<argname>"].Boolorargs["<argname>"](C++ will try to convert it to a boolean) - Has type:
bool - Default to:
false
- Accessible by:
Parser::STORE_FALSE- Accessible by:
args["<argname>"].Boolorargs["<argname>"](C++ will try to convert it to a boolean) - Type:
bool - Default to:
true
- Accessible by:
Here are 4 simple example of how works the cpParser library, with each argument type :
#include <iostream>
#include <string>
#include "cpparser.hpp"
int main(int argc, char* argv[]) {
Parser parser("Example for 'Parser::STORE_ONE_VALUE' argument type");
parser.addArgument(
"-n", // Short flag
"--name", // Long flag
"name", // Key with which you will access value
true, // true if the argument is required, false
// otherwise. Default to false if nothing given
Parser::STORE_ONE_VALUE, // Type of stored argument
{"ain", "tea"}, // Values accepted for the flag,
// if not given, all values are considered correct
"User name" // Description of argument
);
auto args = parser.parseArgs(argc, argv);
// the value is contained in `args["name"]` (c++ will convert it to the right type), but to enforce
// the type, `args["name"].String` is the way to go
std::cout << "Your name is " << args["name"] << std::endl;
return 0;
}#include <iostream>
#include <string>
#include <vector>
#include "cpparser.hpp"
int main(int argc, char* argv[]) {
Parser parser("Example for 'Parser::STORE_MULTIPLE_VALUES' argument type");
parser.addArgument(
"-u",
"--urls",
"urlList",
true,
Parser::STORE_MULTIPLE_VALUES,
"The list of URL"
);
auto args = parser.parseArgs(argc, argv);
for (std::string url: args["urlList"].Vector) {
std::cout << url << std::endl;
}
return 0;
}#include <iostream>
#include <string>
#include <map>
#include "cpparser.hpp"
int main(int argc, char* argv[]) {
// It's the same for 'Parser::STORE_FALSE'
Parser parser("Example for 'Parser::STORE_TRUE' argument type");
parser.addArgument(
"-i",
"--ignore-case",
"ignorecase",
Parser::STORE_TRUE,
"Ignores case"
);
auto args = parser.parseArgs(argc, argv);
if (args["ignorecase"]) {
std::cout << "'Ignore case' flag was given" << std::endl;
} else {
std::cout << "'Ignore case' flag was not given" << std::endl;
}
return 0;
}If you had any problem with compiling/using the library, or if you have any suggestions, please open an issue