This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/app/include/plasp-app/Command.h
Patrick Lühne 9fde2b8e1b
Updated cxxopts to 2.0.0.
Starting from version 2.0.0, cxxopts returns a ParseResult object
instead of storing the results directly within the Options structure.
Additionally, Booleans are handled slightly differently.

These two changes required some minor adjustment of the command-line
argument parsing code.
2017-11-17 00:51:51 +01:00

72 lines
1.6 KiB
C++

#ifndef __PLASP_APP__COMMAND_H
#define __PLASP_APP__COMMAND_H
#include <tuple>
#include <cxxopts.hpp>
#include <plasp-app/Utils.h>
#include <plasp-app/Version.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Command
//
////////////////////////////////////////////////////////////////////////////////////////////////////
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()
: m_options(std::string("plasp ") + Derived::Name, std::string(Derived::Description) + ".")
{
forEach(m_optionGroups,
[&](auto &optionGroup)
{
optionGroup.addTo(m_options);
});
}
void parseOptions(int argc, char **argv)
{
const auto parseResult = m_options.parse(argc, argv);
forEach(m_optionGroups,
[&](auto &optionGroup)
{
optionGroup.read(parseResult);
});
}
static void printVersion()
{
std::cout << Version << std::endl;
}
cxxopts::Options m_options;
std::tuple<OptionGroups...> m_optionGroups;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
#endif