2017-10-13 17:12:33 +02:00
|
|
|
#ifndef __PLASP_APP__COMMAND_H
|
|
|
|
#define __PLASP_APP__COMMAND_H
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <cxxopts.hpp>
|
|
|
|
|
|
|
|
#include <plasp-app/Utils.h>
|
2017-10-13 18:19:34 +02:00
|
|
|
#include <plasp-app/Version.h>
|
2017-10-13 17:12:33 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Command
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-14 01:20:26 +02:00
|
|
|
template<class Derived, class... OptionGroups>
|
2017-10-13 17:12:33 +02:00
|
|
|
class Command
|
|
|
|
{
|
2017-10-14 01:20:26 +02:00
|
|
|
public:
|
|
|
|
void printHelp()
|
2017-10-13 17:12:33 +02:00
|
|
|
{
|
2017-10-14 01:20:26 +02:00
|
|
|
const auto numberOfOptionGroups = std::tuple_size<std::decay_t<decltype(m_optionGroups)>>();
|
|
|
|
|
|
|
|
std::vector<std::string> optionGroupNames;
|
|
|
|
optionGroupNames.reserve(numberOfOptionGroups + 1);
|
|
|
|
optionGroupNames.emplace_back("");
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
2017-10-14 01:20:26 +02:00
|
|
|
{
|
|
|
|
optionGroupNames.emplace_back(optionGroup.Name);
|
2017-10-13 17:12:33 +02:00
|
|
|
});
|
2017-10-14 01:20:26 +02:00
|
|
|
|
|
|
|
std::cout << m_options.help(optionGroupNames) << std::endl;
|
2017-10-13 17:12:33 +02:00
|
|
|
}
|
|
|
|
|
2017-10-14 01:20:26 +02:00
|
|
|
protected:
|
|
|
|
Command()
|
|
|
|
: m_options(std::string("plasp ") + Derived::Name, std::string(Derived::Description) + ".")
|
2017-10-13 17:12:33 +02:00
|
|
|
{
|
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
|
|
|
{
|
2017-10-14 01:20:26 +02:00
|
|
|
optionGroup.addTo(m_options);
|
2017-10-13 17:12:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-14 01:20:26 +02:00
|
|
|
void parseOptions(int argc, char **argv)
|
2017-10-13 18:09:15 +02:00
|
|
|
{
|
2017-10-14 01:20:26 +02:00
|
|
|
m_options.parse(argc, argv);
|
2017-10-13 18:09:15 +02:00
|
|
|
|
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
2017-10-14 01:20:26 +02:00
|
|
|
{
|
|
|
|
optionGroup.parse(m_options);
|
2017-10-13 18:09:15 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-14 01:20:26 +02:00
|
|
|
static void printVersion()
|
2017-10-13 18:19:34 +02:00
|
|
|
{
|
|
|
|
std::cout << Version << std::endl;
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:14:24 +02:00
|
|
|
cxxopts::Options m_options;
|
2017-10-13 17:12:33 +02:00
|
|
|
std::tuple<OptionGroups...> m_optionGroups;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif
|