39 const int argc = (int)args.size();
40 for (
int i = 1; i < argc;) {
45 add =
check(args[i], &args[i + 1], ok, ignoreAppenders);
47 add =
check(args[i],
nullptr, ok, ignoreAppenders);
51 WRITE_ERROR(
"On processing option '" + args[i] +
"':\n " + e.what());
61OptionsParser::check(
const std::string& arg1,
const std::string*
const arg2,
bool& ok,
const bool ignoreAppenders) {
70 const bool append = arg1[0] ==
'+';
72 if (append || arg1[1] ==
'-') {
73 const std::string tmp(arg1.substr(append ? 1 : 2));
74 const std::string::size_type idx1 = tmp.find(
'=');
75 if (append && ignoreAppenders) {
76 return idx1 == std::string::npos ? 2 : 1;
79 if (idx1 != std::string::npos) {
80 ok &= oc.
set(tmp.substr(0, idx1), tmp.substr(idx1 + 1), append);
82 if (arg2 ==
nullptr || (oc.
isBool(tmp) && (*arg2)[0] ==
'-')) {
83 ok &= oc.
set(tmp,
"true");
85 ok &= oc.
set(tmp, *arg2, append);
92 const int len = (int)arg1.size();
93 for (
int i = 1; i < len; i++) {
95 const std::string abbr = arg1.substr(i, 1);
97 if (arg2 ==
nullptr || (*arg2)[0] ==
'-' || i != len - 1) {
98 ok &= oc.
set(abbr,
"true");
100 ok &= oc.
set(abbr, *arg2);
107 if (arg2 ==
nullptr || i != len - 1) {
112 ok &= oc.
set(abbr, *arg2, append);
126 if (arg.size() < 3) {
127 WRITE_ERRORF(
TL(
"Missing value for parameter '%'."), arg.substr(0, 1));
130 return oc.
set(arg.substr(0, 1), arg.substr(2), append);
133 if (arg.size() < 2) {
137 return oc.
set(arg.substr(0, 1), arg.substr(1), append);
145 if (arg1[0] !=
'-' && arg1[0] !=
'+') {
146 WRITE_ERRORF(
TL(
"The parameter '%' is not allowed in this context.\n Switch or parameter name expected."), arg1);
149 if ((arg1[0] ==
'-' && arg1[1] ==
'+') || (arg1[0] ==
'+' && arg1[1] ==
'-')) {
#define WRITE_ERRORF(...)
A storage for options typed value containers)
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
static OptionsCont & getOptions()
Retrieves the options.
static bool parse(const std::vector< std::string > &args, const bool ignoreAppenders=false)
Parses the given command line arguments.
static int check(const std::string &arg1, const std::string *const arg2, bool &ok, const bool ignoreAppenders)
parses the previous arguments
static bool checkParameter(const std::string &arg1)
Returns the whether the given token is an option.
static bool processNonBooleanSingleSwitch(OptionsCont &oc, const std::string &arg, const bool append)
Extracts the parameter directly attached to an option.