Adjust command-line arguments to use '-' consistently instead of no spaces or camelCase
Issue/feature addressed
This MR adjusts command-line arguments to use '-' consistently instead of no spaces or camelCase.
Proposed solution
This is done in a manner that enables the new command line arguments, e.g. --forceoutput
becomes --force-output
, but prints a warning that the command line argument is deprecated (that could be turned into an error in future releases).
Implementation
Since we use boost::program_options
, the general idea is to define a map of deprecated options, e.g.
// Deprecated options: introduced in 5.4.0 to homogenise command-line
// options to use '-' instead of camelCase or no spaces.
std::map<std::string, std::string> deprecated = {
{"forceoutput", "force-output"},
{"noequispaced", "no-equispaced"},
{"useSessionVariables", "use-session-variables"},
{"useSessionExpansion", "use-session-expansion"}
};
which populates options in the po::options_description
object
po::options_description dep;
for (auto &d : deprecated)
{
std::string description = "Deprecated: use --" + d.second;
dep.add_options()(d.first.c_str(), description.c_str());
}
After parsing we set the new options in the po::variables_map
object:
// Deal with deprecated options.
for (auto &d : deprecated)
{
if (vm.count(d.first))
{
std::cerr << "WARNING: --" << d.first << " deprecated: use --"
<< d.second << std::endl;
vm.emplace(d.second, po::variable_value(vm[d.first]));
}
}
Tests
Code and tests have been adjusted to use the new options.
Suggested reviewers
Notes
Please add any other information that could be useful for reviewers.
Checklist
-
Functions and classes, or changes to them, are documented. -
User guide/documentation is updated. -
Changelog is updated. -
Suitable tests added for new functionality. -
Contributed code is correctly formatted. (See the contributing guidelines). -
License added to any new files. -
No extraneous files have been added (e.g. compiler output or test data files).