Showing list of available commands in help message.
This commit is contained in:
@@ -14,12 +14,30 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class... OptionGroups>
|
||||
template<class Derived, class... OptionGroups>
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
void printHelp()
|
||||
{
|
||||
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 << m_options.help(optionGroupNames) << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
Command(cxxopts::Options &&options)
|
||||
: m_options{options}
|
||||
Command()
|
||||
: m_options(std::string("plasp ") + Derived::Name, std::string(Derived::Description) + ".")
|
||||
{
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
@@ -39,24 +57,7 @@ class Command
|
||||
});
|
||||
}
|
||||
|
||||
void printHelp()
|
||||
{
|
||||
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 << m_options.help(optionGroupNames) << std::endl;
|
||||
}
|
||||
|
||||
void printVersion()
|
||||
static void printVersion()
|
||||
{
|
||||
std::cout << Version << std::endl;
|
||||
}
|
||||
|
65
app/include/plasp-app/CommandType.h
Normal file
65
app/include/plasp-app/CommandType.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef __PLASP_APP__COMMAND_TYPE_H
|
||||
#define __PLASP_APP__COMMAND_TYPE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <plasp-app/commands/CommandHelp.h>
|
||||
#include <plasp-app/commands/CommandNormalize.h>
|
||||
#include <plasp-app/commands/CommandTranslate.h>
|
||||
#include <plasp-app/commands/CommandVersion.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Type
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class CommandType
|
||||
{
|
||||
Help,
|
||||
Version,
|
||||
CheckSyntax,
|
||||
Requirements,
|
||||
PrettyPrint,
|
||||
Normalize,
|
||||
Translate
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const std::map<std::string, CommandType> commandNames =
|
||||
{
|
||||
{"help", CommandType::Help},
|
||||
{"-h", CommandType::Help},
|
||||
{"--help", CommandType::Help},
|
||||
{"version", CommandType::Version},
|
||||
{"-v", CommandType::Version},
|
||||
{"--version", CommandType::Version},
|
||||
{"check-syntax", CommandType::CheckSyntax},
|
||||
{"requirements", CommandType::Requirements},
|
||||
{"pretty-print", CommandType::PrettyPrint},
|
||||
{"normalize", CommandType::Normalize},
|
||||
{"translate", CommandType::Translate},
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const auto parseCommandType =
|
||||
[](const std::string &commandString)
|
||||
{
|
||||
const auto matchingCommand = commandNames.find(commandString);
|
||||
|
||||
if (matchingCommand == commandNames.cend())
|
||||
throw std::runtime_error(std::string("“") + commandString + "” is not a plasp command");
|
||||
|
||||
return matchingCommand->second;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using AvailableCommands = std::tuple<CommandTranslate, CommandNormalize, CommandHelp, CommandVersion>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandHelp.h
Normal file
25
app/include/plasp-app/commands/CommandHelp.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_HELP_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_HELP_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Help
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandHelp : public Command<CommandHelp>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "help";
|
||||
static constexpr auto Description = "Display this help message";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
@@ -10,11 +10,13 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandNormalize : public Command<OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
class CommandNormalize : public Command<CommandNormalize, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
CommandNormalize();
|
||||
static constexpr auto Name = "normalize";
|
||||
static constexpr auto Description = "Normalize PDDL to plasp’s custom PDDL format";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
|
@@ -10,11 +10,13 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandTranslate : public Command<OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
class CommandTranslate : public Command<CommandTranslate, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
CommandTranslate();
|
||||
static constexpr auto Name = "translate";
|
||||
static constexpr auto Description = "Translate PDDL and SAS to ASP";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
|
@@ -10,11 +10,13 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandVersion : public Command<>
|
||||
class CommandVersion : public Command<CommandVersion>
|
||||
{
|
||||
public:
|
||||
CommandVersion();
|
||||
static constexpr auto Name = "version";
|
||||
static constexpr auto Description = "Display version information";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user