simplifying a function

Dramatic simplification of legacy code by separating code and data and applying some later C++.
Function removed from Application.cpp as it was in a anonymous namespace and could not easily be subjected to unit testing.
Added ProgramOptionsUtilities.h
This commit is contained in:
berniev
2023-03-08 08:50:46 +10:00
committed by wwmayer
parent eba80267ff
commit de1acd926e
5 changed files with 125 additions and 50 deletions

View File

@@ -51,6 +51,7 @@
#include <QProcessEnvironment>
#include <QStandardPaths>
#include <LibraryVersions.h>
#include <array>
#include <App/MaterialPy.h>
#include <App/MetadataPy.h>
@@ -107,6 +108,7 @@
#include "Part.h"
#include "PartPy.h"
#include "Placement.h"
#include "ProgramOptionsUtilities.h"
#include "Property.h"
#include "PropertyContainer.h"
#include "PropertyExpressionEngine.h"
@@ -2145,53 +2147,6 @@ void Application::initTypes()
}
namespace {
pair<string, string> customSyntax(const string& s)
{
#if defined(FC_OS_MACOSX)
if (s.find("-psn_") == 0)
return make_pair(string("psn"), s.substr(5));
#endif
if (s.find("-display") == 0)
return make_pair(string("display"), string("null"));
else if (s.find("-style") == 0)
return make_pair(string("style"), string("null"));
else if (s.find("-graphicssystem") == 0)
return make_pair(string("graphicssystem"), string("null"));
else if (s.find("-widgetcount") == 0)
return make_pair(string("widgetcount"), string(""));
else if (s.find("-geometry") == 0)
return make_pair(string("geometry"), string("null"));
else if (s.find("-font") == 0)
return make_pair(string("font"), string("null"));
else if (s.find("-fn") == 0)
return make_pair(string("fn"), string("null"));
else if (s.find("-background") == 0)
return make_pair(string("background"), string("null"));
else if (s.find("-bg") == 0)
return make_pair(string("bg"), string("null"));
else if (s.find("-foreground") == 0)
return make_pair(string("foreground"), string("null"));
else if (s.find("-fg") == 0)
return make_pair(string("fg"), string("null"));
else if (s.find("-button") == 0)
return make_pair(string("button"), string("null"));
else if (s.find("-btn") == 0)
return make_pair(string("btn"), string("null"));
else if (s.find("-name") == 0)
return make_pair(string("name"), string("null"));
else if (s.find("-title") == 0)
return make_pair(string("title"), string("null"));
else if (s.find("-visual") == 0)
return make_pair(string("visual"), string("null"));
// else if (s.find("-ncols") == 0)
// return make_pair(string("ncols"), boost::program_options::value<int>(1));
// else if (s.find("-cmap") == 0)
// return make_pair(string("cmap"), string("null"));
else if ('@' == s[0])
return std::make_pair(string("response-file"), s.substr(1));
else
return make_pair(string(), string());
}
void parseProgramOptions(int ac, char ** av, const string& exe, variables_map& vm)
{
@@ -2311,7 +2266,7 @@ void parseProgramOptions(int ac, char ** av, const string& exe, variables_map& v
try {
store( boost::program_options::command_line_parser(args).
options(cmdline_options).positional(p).extra_parser(customSyntax).run(), vm);
options(cmdline_options).positional(p).extra_parser(Util::customSyntax).run(), vm);
std::ifstream ifs("FreeCAD.cfg");
if (ifs)
@@ -2358,7 +2313,7 @@ void parseProgramOptions(int ac, char ** av, const string& exe, variables_map& v
copy(tok.begin(), tok.end(), back_inserter(args));
// Parse the file and store the options
store( boost::program_options::command_line_parser(args).
options(cmdline_options).positional(p).extra_parser(customSyntax).run(), vm);
options(cmdline_options).positional(p).extra_parser(Util::customSyntax).run(), vm);
}
}