diff --git a/app/include/plasp-app/Command.h b/app/include/plasp-app/Command.h index 96fbf87..a9b02b1 100644 --- a/app/include/plasp-app/Command.h +++ b/app/include/plasp-app/Command.h @@ -35,6 +35,23 @@ class Command }); } + void printHelp(cxxopts::Options &options) + { + const auto numberOfOptionGroups = std::tuple_size>(); + + std::vector optionGroupNames; + optionGroupNames.reserve(numberOfOptionGroups + 1); + optionGroupNames.emplace_back(""); + + forEach(m_optionGroups, + [&](auto &optionGroup) + { + optionGroupNames.emplace_back(optionGroup.Name); + }); + + std::cout << options.help(optionGroupNames) << std::endl; + } + std::tuple m_optionGroups; }; diff --git a/app/include/plasp-app/OptionGroups.h b/app/include/plasp-app/OptionGroups.h index ca0c44b..885bf2d 100644 --- a/app/include/plasp-app/OptionGroups.h +++ b/app/include/plasp-app/OptionGroups.h @@ -27,6 +27,8 @@ class OptionException : public pddl::Exception struct OptionGroupBasic { + static constexpr const auto Name = "basic"; + void addTo(cxxopts::Options &options); void parse(cxxopts::Options &options); @@ -39,6 +41,8 @@ struct OptionGroupBasic struct OptionGroupOutput { + static constexpr const auto Name = "output"; + void addTo(cxxopts::Options &options); void parse(cxxopts::Options &options); @@ -50,6 +54,8 @@ struct OptionGroupOutput struct OptionGroupParser { + static constexpr const auto Name = "parser"; + void addTo(cxxopts::Options &options); void parse(cxxopts::Options &options); diff --git a/app/src/plasp-app/OptionGroups.cpp b/app/src/plasp-app/OptionGroups.cpp index aea6dc7..efe4d27 100644 --- a/app/src/plasp-app/OptionGroups.cpp +++ b/app/src/plasp-app/OptionGroups.cpp @@ -8,7 +8,7 @@ void OptionGroupBasic::addTo(cxxopts::Options &options) { - options.add_options("basic") + options.add_options(Name) ("h,help", "Display this help message") ("v,version", "Display version information") ("warnings-as-errors", "Treat warnings as errors"); @@ -27,7 +27,7 @@ void OptionGroupBasic::parse(cxxopts::Options &options) void OptionGroupOutput::addTo(cxxopts::Options &options) { - options.add_options("output") + options.add_options(Name) ("color", "Colorize output (always, never, auto)", cxxopts::value()->default_value("auto")) ("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value()->default_value("info")); } @@ -63,7 +63,7 @@ void OptionGroupOutput::parse(cxxopts::Options &options) void OptionGroupParser::addTo(cxxopts::Options &options) { - options.add_options("parser") + options.add_options(Name) ("i,input", "Input files (in PDDL or SAS format)", cxxopts::value>()) ("parsing-mode", "Parsing mode (strict, compatibility)", cxxopts::value()->default_value("strict")) ("l,language", "Input language (pddl, sas, auto)", cxxopts::value()->default_value("auto")); diff --git a/app/src/plasp-app/commands/CommandTranslate.cpp b/app/src/plasp-app/commands/CommandTranslate.cpp index 2b243ac..e631fed 100644 --- a/app/src/plasp-app/commands/CommandTranslate.cpp +++ b/app/src/plasp-app/commands/CommandTranslate.cpp @@ -37,15 +37,7 @@ int CommandTranslate::run(int argc, char **argv) cxxopts::Options options("plasp translate", "Translate PDDL to ASP."); addOptionGroupsTo(options); - - const auto printHelp = - [&]() - { - std::cout << options.help({"", "basic", "output", "parser"}); - }; - options.parse(argc, argv); - parseOptionGroups(options); const auto &basicOptions = std::get(m_optionGroups); @@ -54,7 +46,7 @@ int CommandTranslate::run(int argc, char **argv) if (basicOptions.help) { - printHelp(); + printHelp(options); return EXIT_SUCCESS; } @@ -110,7 +102,7 @@ int CommandTranslate::run(int argc, char **argv) { logger.log(colorlog::Priority::Error, "unknown input language"); std::cout << std::endl; - printHelp(); + printHelp(options); return EXIT_FAILURE; }