aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/arg_parser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtests/arg_parser.cc')
-rw-r--r--libtests/arg_parser.cc105
1 files changed, 42 insertions, 63 deletions
diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc
index 4b10709e..8b4d556a 100644
--- a/libtests/arg_parser.cc
+++ b/libtests/arg_parser.cc
@@ -1,8 +1,8 @@
#include <qpdf/QPDFArgParser.hh>
-#include <qpdf/QUtil.hh>
#include <qpdf/QPDFUsage.hh>
-#include <iostream>
+#include <qpdf/QUtil.hh>
#include <cstring>
+#include <iostream>
#ifdef NDEBUG
// We need assert even in a release build for test code.
@@ -59,39 +59,39 @@ ArgParser::initOptions()
char const* choices[] = {"pig", "boar", "sow", 0};
ap.addChoices("oink", p(&ArgParser::handleOink), true, choices);
ap.selectHelpOptionTable();
- ap.addBare("version", [this](){ output("3.14159"); });
+ ap.addBare("version", [this]() { output("3.14159"); });
ap.selectMainOptionTable();
ap.addBare("quack", b(&ArgParser::startQuack));
ap.registerOptionTable("quack", b(&ArgParser::endQuack));
ap.addPositional(p(&ArgParser::getQuack));
ap.addFinalCheck(b(&ArgParser::finalChecks));
ap.selectMainOptionTable();
- ap.addBare("baaa", [this](){ this->ap.selectOptionTable("baaa"); });
+ ap.addBare("baaa", [this]() { this->ap.selectOptionTable("baaa"); });
ap.registerOptionTable("baaa", nullptr);
- ap.addBare("ewe", [this](){ output("you"); });
- ap.addBare("ram", [this](){ output("ram"); });
+ ap.addBare("ewe", [this]() { output("you"); });
+ ap.addBare("ram", [this]() { output("ram"); });
ap.selectMainOptionTable();
- ap.addBare("sheep", [this](){ this->ap.selectOptionTable("sheep"); });
+ ap.addBare("sheep", [this]() { this->ap.selectOptionTable("sheep"); });
ap.registerOptionTable("sheep", nullptr);
ap.addHelpFooter("For more help, read the manual.\n");
ap.addHelpTopic(
- "quack", "Quack Options",
+ "quack",
+ "Quack Options",
"Just put stuff after quack to get a count at the end.\n");
ap.addHelpTopic(
- "baaa", "Baaa Options",
+ "baaa",
+ "Baaa Options",
"Ewe can do sheepish things.\n"
"For example, ewe can add more ram to your computer.\n");
- ap.addOptionHelp("--ewe", "baaa",
- "just for ewe", "You are not a ewe.\n");
+ ap.addOptionHelp("--ewe", "baaa", "just for ewe", "You are not a ewe.\n");
ap.addOptionHelp("--ram", "baaa", "curly horns", "");
}
void
ArgParser::output(std::string const& msg)
{
- if (! this->ap.isCompleting())
- {
+ if (!this->ap.isCompleting()) {
std::cout << msg << std::endl;
}
}
@@ -130,10 +130,8 @@ void
ArgParser::startQuack()
{
this->ap.selectOptionTable("quack");
- if (this->ap.isCompleting())
- {
- if (this->ap.isCompleting() && (this->ap.argsLeft() == 0))
- {
+ if (this->ap.isCompleting()) {
+ if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) {
this->ap.insertCompletion("something");
this->ap.insertCompletion("anything");
}
@@ -145,8 +143,7 @@ void
ArgParser::getQuack(std::string const& p)
{
++this->quacks;
- if (this->ap.isCompleting() && (this->ap.argsLeft() == 0))
- {
+ if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) {
this->ap.insertCompletion(
std::string("thing-") + QUtil::int_to_string(this->quacks));
return;
@@ -170,74 +167,56 @@ void
ArgParser::test_exceptions()
{
auto err = [](char const* msg, std::function<void()> fn) {
- try
- {
+ try {
fn();
assert(msg == nullptr);
- }
- catch (std::exception& e)
- {
+ } catch (std::exception& e) {
std::cout << msg << ": " << e.what() << std::endl;
}
};
err("duplicate handler", [this]() {
ap.selectMainOptionTable();
- ap.addBare("potato", [](){});
+ ap.addBare("potato", []() {});
});
err("duplicate handler", [this]() {
ap.selectOptionTable("baaa");
- ap.addBare("ram", [](){});
- });
- err("duplicate table", [this]() {
- ap.registerOptionTable("baaa", nullptr);
- });
- err("unknown table", [this]() {
- ap.selectOptionTable("aardvark");
- });
- err("add existing help topic", [this]() {
- ap.addHelpTopic("baaa", "potato", "salad");
- });
- err("add reserved help topic", [this]() {
- ap.addHelpTopic("all", "potato", "salad");
- });
- err("add to unknown topic", [this]() {
- ap.addOptionHelp("--new", "oops", "potato", "salad");
- });
- err("bad option for help", [this]() {
- ap.addOptionHelp("nodash", "baaa", "potato", "salad");
- });
- err("bad topic for help", [this]() {
- ap.addHelpTopic("--dashes", "potato", "salad");
- });
- err("duplicate option help", [this]() {
- ap.addOptionHelp("--ewe", "baaa", "potato", "salad");
+ ap.addBare("ram", []() {});
});
+ err("duplicate table",
+ [this]() { ap.registerOptionTable("baaa", nullptr); });
+ err("unknown table", [this]() { ap.selectOptionTable("aardvark"); });
+ err("add existing help topic",
+ [this]() { ap.addHelpTopic("baaa", "potato", "salad"); });
+ err("add reserved help topic",
+ [this]() { ap.addHelpTopic("all", "potato", "salad"); });
+ err("add to unknown topic",
+ [this]() { ap.addOptionHelp("--new", "oops", "potato", "salad"); });
+ err("bad option for help",
+ [this]() { ap.addOptionHelp("nodash", "baaa", "potato", "salad"); });
+ err("bad topic for help",
+ [this]() { ap.addHelpTopic("--dashes", "potato", "salad"); });
+ err("duplicate option help",
+ [this]() { ap.addOptionHelp("--ewe", "baaa", "potato", "salad"); });
err("invalid choice handler to unknown", [this]() {
- ap.addInvalidChoiceHandler(
- "elephant", [](std::string const&){});
+ ap.addInvalidChoiceHandler("elephant", [](std::string const&) {});
});
}
-int main(int argc, char* argv[])
+int
+main(int argc, char* argv[])
{
ArgParser ap(argc, argv);
- if ((argc == 2) && (strcmp(argv[1], "exceptions") == 0))
- {
+ if ((argc == 2) && (strcmp(argv[1], "exceptions") == 0)) {
ap.test_exceptions();
return 0;
}
- try
- {
+ try {
ap.parseArgs();
- }
- catch (QPDFUsage& e)
- {
+ } catch (QPDFUsage& e) {
std::cerr << "usage: " << e.what() << std::endl;
exit(2);
- }
- catch (std::exception& e)
- {
+ } catch (std::exception& e) {
std::cerr << "exception: " << e.what() << std::endl;
exit(3);
}