Browse Source

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.
master
Patrick Lühne 4 years ago
parent
commit
9fde2b8e1b
No known key found for this signature in database GPG Key ID: 5F3611E97A70ABF
  1. 4
      app/include/plasp-app/Command.h
  2. 6
      app/include/plasp-app/OptionGroups.h
  3. 24
      app/src/plasp-app/OptionGroups.cpp
  4. 2
      lib/cxxopts

4
app/include/plasp-app/Command.h

@ -48,12 +48,12 @@ class Command
void parseOptions(int argc, char **argv)
{
m_options.parse(argc, argv);
const auto parseResult = m_options.parse(argc, argv);
forEach(m_optionGroups,
[&](auto &optionGroup)
{
optionGroup.parse(m_options);
optionGroup.read(parseResult);
});
}

6
app/include/plasp-app/OptionGroups.h

@ -30,7 +30,7 @@ struct OptionGroupBasic
static constexpr const auto Name = "basic";
void addTo(cxxopts::Options &options);
void parse(cxxopts::Options &options);
void read(const cxxopts::ParseResult &parseResult);
bool help = false;
bool version = false;
@ -44,7 +44,7 @@ struct OptionGroupOutput
static constexpr const auto Name = "output";
void addTo(cxxopts::Options &options);
void parse(cxxopts::Options &options);
void read(const cxxopts::ParseResult &parseResult);
colorlog::ColorStream::ColorPolicy colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
colorlog::Priority logPriority = colorlog::Priority::Info;
@ -57,7 +57,7 @@ struct OptionGroupParser
static constexpr const auto Name = "parser";
void addTo(cxxopts::Options &options);
void parse(cxxopts::Options &options);
void read(const cxxopts::ParseResult &parseResult);
std::vector<std::string> inputFiles;
pddl::Mode parsingMode = pddl::Mode::Strict;

24
app/src/plasp-app/OptionGroups.cpp

@ -21,11 +21,11 @@ void OptionGroupBasic::addTo(cxxopts::Options &options)
////////////////////////////////////////////////////////////////////////////////////////////////////
void OptionGroupBasic::parse(cxxopts::Options &options)
void OptionGroupBasic::read(const cxxopts::ParseResult &parseResult)
{
help = options["help"].as<bool>();
version = options["version"].as<bool>();
warningsAsErrors = options["warnings-as-errors"].as<bool>();
help = (parseResult.count("help") > 0);
version = (parseResult.count("version") > 0);
warningsAsErrors = (parseResult.count("warnings-as-errors") > 0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -44,9 +44,9 @@ void OptionGroupOutput::addTo(cxxopts::Options &options)
////////////////////////////////////////////////////////////////////////////////////////////////////
void OptionGroupOutput::parse(cxxopts::Options &options)
void OptionGroupOutput::read(const cxxopts::ParseResult &parseResult)
{
const auto colorPolicyString = options["color"].as<std::string>();
const auto colorPolicyString = parseResult["color"].as<std::string>();
if (colorPolicyString == "auto")
colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
@ -57,7 +57,7 @@ void OptionGroupOutput::parse(cxxopts::Options &options)
else
throw OptionException("unknown color policy “" + colorPolicyString + "");
const auto logPriorityString = options["log-priority"].as<std::string>();
const auto logPriorityString = parseResult["log-priority"].as<std::string>();
try
{
@ -88,19 +88,19 @@ void OptionGroupParser::addTo(cxxopts::Options &options)
////////////////////////////////////////////////////////////////////////////////////////////////////
void OptionGroupParser::parse(cxxopts::Options &options)
void OptionGroupParser::read(const cxxopts::ParseResult &parseResult)
{
const auto parsingModeString = options["parsing-mode"].as<std::string>();
const auto parsingModeString = parseResult["parsing-mode"].as<std::string>();
if (parsingModeString == "compatibility")
parsingMode = pddl::Mode::Compatibility;
else if (parsingModeString != "strict")
throw OptionException("unknown parsing mode “" + parsingModeString + "");
if (options.count("input"))
inputFiles = options["input"].as<std::vector<std::string>>();
if (parseResult.count("input"))
inputFiles = parseResult["input"].as<std::vector<std::string>>();
const auto languageName = options["language"].as<std::string>();
const auto languageName = parseResult["language"].as<std::string>();
language = plasp::Language::fromString(languageName);
if (language == plasp::Language::Type::Unknown)

2
lib/cxxopts

@ -1 +1 @@
Subproject commit 0b7686949d01f6475cc13ba0693725aefb76fc0c
Subproject commit 8893afe13cc47dd0be4f25b5ae491e652c146098
Loading…
Cancel
Save