From: Arvin Schnell Date: Thu, 10 Apr 2014 14:41:17 +0000 (+0200) Subject: - more verbose error messages X-Git-Tag: v0.2.2~1^2~2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=ccc026aa64d7ebfafb487723932044ea0ee00dfc;p=thirdparty%2Fsnapper.git - more verbose error messages --- diff --git a/client/misc.cc b/client/misc.cc index 7fc576f9..c4b043b8 100644 --- a/client/misc.cc +++ b/client/misc.cc @@ -160,3 +160,39 @@ show_userdata(const map& userdata) return s; } + + +map +read_configdata(const list& l, const map& old) +{ + if (l.empty()) + { + cerr << _("Empty configdata.") << endl; + exit(EXIT_FAILURE); + } + + map configdata = old; + + for (list::const_iterator it = l.begin(); it != l.end(); ++it) + { + string::size_type pos = it->find("="); + if (pos == string::npos) + { + cerr << sformat(_("Configdata '%s' does not include '=' sign."), it->c_str()) << endl; + exit(EXIT_FAILURE); + } + + string key = boost::trim_copy(it->substr(0, pos)); + string value = boost::trim_copy(it->substr(pos + 1)); + + if (key.empty()) + { + cerr << sformat(_("Configdata '%s' has empty key."), it->c_str()) << endl; + exit(EXIT_FAILURE); + } + + configdata[key] = value; + } + + return configdata; +} diff --git a/client/misc.h b/client/misc.h index ae89c950..924a41fb 100644 --- a/client/misc.h +++ b/client/misc.h @@ -44,3 +44,6 @@ read_userdata(const string& s, const map& old = map& userdata); +map +read_configdata(const list& l, const map& old = map()); + diff --git a/client/snapper.cc b/client/snapper.cc index e907b397..5edf602b 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -354,24 +354,7 @@ command_set_config(DBus::Connection* conn, Snapper* snapper) exit(EXIT_FAILURE); } - map raw; - - while (getopts.hasArgs()) - { - string arg = getopts.popArg(); - - string::size_type pos = arg.find("="); - if (pos == string::npos) - { - cerr << _("Invalid configdata.") << endl; - exit(EXIT_FAILURE); - } - - string key = boost::trim_copy(arg.substr(0, pos)); - string value = boost::trim_copy(arg.substr(pos + 1)); - - raw[key] = value; - } + map raw = read_configdata(getopts.getArgs()); if (no_dbus) { diff --git a/client/utils/GetOpts.h b/client/utils/GetOpts.h index 4725fe26..78154af6 100644 --- a/client/utils/GetOpts.h +++ b/client/utils/GetOpts.h @@ -2,6 +2,7 @@ #include #include #include +#include class GetOpts @@ -24,6 +25,10 @@ public: const char* popArg() { return argv[optind++]; } + std::list getArgs() const { + return std::list(&argv[optind], &argv[argc]); + } + private: int argc;