Main.cpp now has ann example for the automatic documentation

This commit is contained in:
Leonetienne 2021-06-04 02:31:30 +02:00
parent abcae7ddf7
commit 351ffd2653

View File

@ -6,57 +6,27 @@ using namespace Hazelnp;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
while (1) Hazelnupp nupp;
{
// Mock command-line params
std::vector<const char*> testArgv = {
"meinpfad",
"-w",
"-99",
"--alfred",
"apfel",
"banane",
"triangle",
"--numbers",
"1",
"2",
"3",
"4",
"5",
};
argc = testArgv.size(); nupp.SetBriefDescription("This is the testing application for Hazelnupp.");
argv = const_cast<char**>(testArgv.data());
// Prepare Hazelnupp parser nupp.RegisterDescription("--help", "This will display the parameter documentation.");
Hazelnupp args; nupp.RegisterDescription("--force", "Just forces it.");
nupp.RegisterDescription("--width", "The width of something...");
nupp.RegisterDescription("--name", "The names to target");
nupp.RegisterDescription("--fruit", "The fruit to use");
ParamConstraint pc; nupp.RegisterAbbreviation("-f", "--force");
pc.key = "--alfredo"; nupp.RegisterAbbreviation("-w", "--width");
pc.constrainType = true; nupp.RegisterAbbreviation("-h", "--height");
pc.wantedType = DATA_TYPE::LIST;
pc.required = true;
pc.defaultValue = { "coca cola", "fanta" };
args.RegisterConstraints({ nupp.RegisterConstraints({
pc ParamConstraint::TypeSafety("--width", DATA_TYPE::FLOAT),
ParamConstraint("--name", true, DATA_TYPE::LIST, {"peter", "hannes"}, true),
ParamConstraint("--fruit", true, DATA_TYPE::STRING, {}, true)
}); });
args.RegisterAbbreviation("-w", "--word"); nupp.Parse(argc, argv);
// Parse
args.Parse(argc, argv);
// Use
if (args.HasParam("--alfredo"))
{
std::cout << args["--alfredo"].GetInt32() << std::endl;
}
else
{
std::cout << "No --alfredo!" << std::endl;
}
}
return 0; return 0;
} }