Made option group parsing more uniform.
This commit is contained in:
43
app/include/plasp-app/Command.h
Normal file
43
app/include/plasp-app/Command.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef __PLASP_APP__COMMAND_H
|
||||
#define __PLASP_APP__COMMAND_H
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <plasp-app/Utils.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class... OptionGroups>
|
||||
class Command
|
||||
{
|
||||
protected:
|
||||
void addOptionGroupsTo(cxxopts::Options &options)
|
||||
{
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
{
|
||||
optionGroup.addTo(options);
|
||||
});
|
||||
}
|
||||
|
||||
void parseOptionGroups(cxxopts::Options &options)
|
||||
{
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
{
|
||||
optionGroup.parse(options);
|
||||
});
|
||||
}
|
||||
|
||||
std::tuple<OptionGroups...> m_optionGroups;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
@@ -1,29 +0,0 @@
|
||||
#ifndef __PLASP_APP__COMMANDS_H
|
||||
#define __PLASP_APP__COMMANDS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Commands
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class Command
|
||||
{
|
||||
Help,
|
||||
Version,
|
||||
CheckSyntax,
|
||||
Requirements,
|
||||
PrettyPrint,
|
||||
Normalize,
|
||||
Translate
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Command parseCommand(const std::string &commandString);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
#ifndef __PLASP_APP__COMMON_OPTIONS_H
|
||||
#define __PLASP_APP__COMMON_OPTIONS_H
|
||||
#ifndef __PLASP_APP__OPTION_GROUPS_H
|
||||
#define __PLASP_APP__OPTION_GROUPS_H
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Common Options
|
||||
// Option Groups
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -25,14 +25,12 @@ class OptionException : public pddl::Exception
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addBasicOptions(cxxopts::Options &options);
|
||||
void addOutputOptions(cxxopts::Options &options);
|
||||
void addParserOptions(cxxopts::Options &options);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct BasicOptions
|
||||
struct OptionGroupBasic
|
||||
{
|
||||
void addTo(cxxopts::Options &options);
|
||||
void parse(cxxopts::Options &options);
|
||||
void printHelp(std::ostream &stream);
|
||||
|
||||
bool help = false;
|
||||
bool version = false;
|
||||
bool warningsAsErrors = false;
|
||||
@@ -40,16 +38,24 @@ struct BasicOptions
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct OutputOptions
|
||||
struct OptionGroupOutput
|
||||
{
|
||||
void addTo(cxxopts::Options &options);
|
||||
void parse(cxxopts::Options &options);
|
||||
void printHelp(std::ostream &stream);
|
||||
|
||||
colorlog::ColorStream::ColorPolicy colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
|
||||
colorlog::Priority logPriority = colorlog::Priority::Info;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ParserOptions
|
||||
struct OptionGroupParser
|
||||
{
|
||||
void addTo(cxxopts::Options &options);
|
||||
void parse(cxxopts::Options &options);
|
||||
void printHelp(std::ostream &stream);
|
||||
|
||||
std::vector<std::string> inputFiles;
|
||||
pddl::Mode parsingMode = pddl::Mode::Strict;
|
||||
plasp::Language::Type language = plasp::Language::Type::Automatic;
|
||||
@@ -57,10 +63,4 @@ struct ParserOptions
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BasicOptions parseBasicOptions(cxxopts::Options &options);
|
||||
OutputOptions parseOutputOptions(cxxopts::Options &options);
|
||||
ParserOptions parseParserOptions(cxxopts::Options &options);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
46
app/include/plasp-app/Utils.h
Normal file
46
app/include/plasp-app/Utils.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef __PLASP_APP__UTILS_H
|
||||
#define __PLASP_APP__UTILS_H
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <std::size_t... Index>
|
||||
auto makeIndexDispatcher(std::index_sequence<Index...>)
|
||||
{
|
||||
return
|
||||
[](auto &&f)
|
||||
{
|
||||
(f(std::integral_constant<std::size_t, Index>{}), ...);
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <std::size_t N>
|
||||
auto makeIndexDispatcher()
|
||||
{
|
||||
return makeIndexDispatcher(std::make_index_sequence<N>{});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Tuple, typename Functor>
|
||||
void forEach(Tuple &&tuple, Functor &&functor)
|
||||
{
|
||||
constexpr auto n = std::tuple_size<std::decay_t<Tuple>>::value;
|
||||
auto dispatcher = makeIndexDispatcher<n>();
|
||||
dispatcher(
|
||||
[&functor, &tuple](auto index)
|
||||
{
|
||||
functor(std::get<index>(std::forward<Tuple>(tuple)));
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
21
app/include/plasp-app/commands/CommandTranslate.h
Normal file
21
app/include/plasp-app/commands/CommandTranslate.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__TRANSLATE_H
|
||||
#define __PLASP_APP__COMMANDS__TRANSLATE_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Translate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandTranslate : public Command<OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
@@ -1,6 +0,0 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__TRANSLATE_H
|
||||
#define __PLASP_APP__COMMANDS__TRANSLATE_H
|
||||
|
||||
int translate(int argc, char **argv);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user