Refactored printing help messages in commands.
This commit is contained in:
parent
db7ea6f2fe
commit
abdc4e31dc
@ -35,6 +35,23 @@ class Command
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printHelp(cxxopts::Options &options)
|
||||||
|
{
|
||||||
|
const auto numberOfOptionGroups = std::tuple_size<std::decay_t<decltype(m_optionGroups)>>();
|
||||||
|
|
||||||
|
std::vector<std::string> 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<OptionGroups...> m_optionGroups;
|
std::tuple<OptionGroups...> m_optionGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ class OptionException : public pddl::Exception
|
|||||||
|
|
||||||
struct OptionGroupBasic
|
struct OptionGroupBasic
|
||||||
{
|
{
|
||||||
|
static constexpr const auto Name = "basic";
|
||||||
|
|
||||||
void addTo(cxxopts::Options &options);
|
void addTo(cxxopts::Options &options);
|
||||||
void parse(cxxopts::Options &options);
|
void parse(cxxopts::Options &options);
|
||||||
|
|
||||||
@ -39,6 +41,8 @@ struct OptionGroupBasic
|
|||||||
|
|
||||||
struct OptionGroupOutput
|
struct OptionGroupOutput
|
||||||
{
|
{
|
||||||
|
static constexpr const auto Name = "output";
|
||||||
|
|
||||||
void addTo(cxxopts::Options &options);
|
void addTo(cxxopts::Options &options);
|
||||||
void parse(cxxopts::Options &options);
|
void parse(cxxopts::Options &options);
|
||||||
|
|
||||||
@ -50,6 +54,8 @@ struct OptionGroupOutput
|
|||||||
|
|
||||||
struct OptionGroupParser
|
struct OptionGroupParser
|
||||||
{
|
{
|
||||||
|
static constexpr const auto Name = "parser";
|
||||||
|
|
||||||
void addTo(cxxopts::Options &options);
|
void addTo(cxxopts::Options &options);
|
||||||
void parse(cxxopts::Options &options);
|
void parse(cxxopts::Options &options);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
void OptionGroupBasic::addTo(cxxopts::Options &options)
|
void OptionGroupBasic::addTo(cxxopts::Options &options)
|
||||||
{
|
{
|
||||||
options.add_options("basic")
|
options.add_options(Name)
|
||||||
("h,help", "Display this help message")
|
("h,help", "Display this help message")
|
||||||
("v,version", "Display version information")
|
("v,version", "Display version information")
|
||||||
("warnings-as-errors", "Treat warnings as errors");
|
("warnings-as-errors", "Treat warnings as errors");
|
||||||
@ -27,7 +27,7 @@ void OptionGroupBasic::parse(cxxopts::Options &options)
|
|||||||
|
|
||||||
void OptionGroupOutput::addTo(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<std::string>()->default_value("auto"))
|
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
|
||||||
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ void OptionGroupOutput::parse(cxxopts::Options &options)
|
|||||||
|
|
||||||
void OptionGroupParser::addTo(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<std::vector<std::string>>())
|
("i,input", "Input files (in PDDL or SAS format)", cxxopts::value<std::vector<std::string>>())
|
||||||
("parsing-mode", "Parsing mode (strict, compatibility)", cxxopts::value<std::string>()->default_value("strict"))
|
("parsing-mode", "Parsing mode (strict, compatibility)", cxxopts::value<std::string>()->default_value("strict"))
|
||||||
("l,language", "Input language (pddl, sas, auto)", cxxopts::value<std::string>()->default_value("auto"));
|
("l,language", "Input language (pddl, sas, auto)", cxxopts::value<std::string>()->default_value("auto"));
|
||||||
|
@ -37,15 +37,7 @@ int CommandTranslate::run(int argc, char **argv)
|
|||||||
cxxopts::Options options("plasp translate", "Translate PDDL to ASP.");
|
cxxopts::Options options("plasp translate", "Translate PDDL to ASP.");
|
||||||
|
|
||||||
addOptionGroupsTo(options);
|
addOptionGroupsTo(options);
|
||||||
|
|
||||||
const auto printHelp =
|
|
||||||
[&]()
|
|
||||||
{
|
|
||||||
std::cout << options.help({"", "basic", "output", "parser"});
|
|
||||||
};
|
|
||||||
|
|
||||||
options.parse(argc, argv);
|
options.parse(argc, argv);
|
||||||
|
|
||||||
parseOptionGroups(options);
|
parseOptionGroups(options);
|
||||||
|
|
||||||
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
||||||
@ -54,7 +46,7 @@ int CommandTranslate::run(int argc, char **argv)
|
|||||||
|
|
||||||
if (basicOptions.help)
|
if (basicOptions.help)
|
||||||
{
|
{
|
||||||
printHelp();
|
printHelp(options);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +102,7 @@ int CommandTranslate::run(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
logger.log(colorlog::Priority::Error, "unknown input language");
|
logger.log(colorlog::Priority::Error, "unknown input language");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
printHelp();
|
printHelp(options);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user