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
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template<class... OptionGroups>
|
|
|
|
class Command
|
|
|
|
{
|
|
|
|
protected:
|
2017-10-13 18:14:24 +02:00
|
|
|
Command(cxxopts::Options &&options)
|
|
|
|
: m_options{options}
|
2017-10-13 17:12:33 +02:00
|
|
|
{
|
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
|
|
|
{
|
2017-10-13 18:14:24 +02:00
|
|
|
optionGroup.addTo(m_options);
|
2017-10-13 17:12:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:14:24 +02:00
|
|
|
void parseOptions(int argc, char **argv)
|
2017-10-13 17:12:33 +02:00
|
|
|
{
|
2017-10-13 18:14:24 +02:00
|
|
|
m_options.parse(argc, argv);
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
|
|
|
{
|
2017-10-13 18:14:24 +02:00
|
|
|
optionGroup.parse(m_options);
|
2017-10-13 17:12:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:14:24 +02:00
|
|
|
void printHelp()
|
2017-10-13 18:09:15 +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("");
|
|
|
|
|
|
|
|
forEach(m_optionGroups,
|
|
|
|
[&](auto &optionGroup)
|
|
|
|
{
|
|
|
|
optionGroupNames.emplace_back(optionGroup.Name);
|
|
|
|
});
|
|
|
|
|
2017-10-13 18:14:24 +02:00
|
|
|
std::cout << m_options.help(optionGroupNames) << std::endl;
|
2017-10-13 18:09:15 +02:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:19:34 +02:00
|
|
|
void printVersion()
|
|
|
|
{
|
|
|
|
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
|