Simple command-line argument parser library for C++.
- Can only handle arguments of following format
--input=23
--transform
- Cannot handle arguments with same option. Example
--input=1 --input=2
-
Just include the file
args.hpp
. -
For sample input arguments
--input=34 --transform
.
args::args args;
//argc and argv are parameters of main function
args.parse(argc,argv);
//Get value as of option as string
std::string str = args["input"].value();
//Get value of option as integer
int inputValue = args["input"].value_as<int>();
//Check argument exists or not
if(args["transform"){
}
if(args["input"){
}
parse()
function returns bool if found any errors parsing arguments.- If you try to access value of argument that doesn't exist then exception will be thrown.
- So check whether argument exist or not before accessing value or
enclose the code in
try-catch
block. - Exception will be thrown if you try to acess value of flag (
--transform
).