]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- more verbose error messages
authorArvin Schnell <aschnell@suse.de>
Thu, 10 Apr 2014 14:41:17 +0000 (16:41 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 10 Apr 2014 14:41:17 +0000 (16:41 +0200)
client/misc.cc
client/misc.h
client/snapper.cc
client/utils/GetOpts.h

index 7fc576f95a031599b5078a37f14cec908d073f6c..c4b043b8a36577e5c0d56e9174e96fcbbed4e5a4 100644 (file)
@@ -160,3 +160,39 @@ show_userdata(const map<string, string>& userdata)
 
     return s;
 }
+
+
+map<string, string>
+read_configdata(const list<string>& l, const map<string, string>& old)
+{
+    if (l.empty())
+    {
+       cerr << _("Empty configdata.") << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    map<string, string> configdata = old;
+
+    for (list<string>::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;
+}
index ae89c9507d766c9b61387a7f51c8d029476ef86a..924a41fbfbf18997800685f35d4d1ab1de474198 100644 (file)
@@ -44,3 +44,6 @@ read_userdata(const string& s, const map<string, string>& old = map<string, stri
 string
 show_userdata(const map<string, string>& userdata);
 
+map<string, string>
+read_configdata(const list<string>& l, const map<string, string>& old = map<string, string>());
+
index e907b397401430c6178f0ff660d61498f5df7313..5edf602baf5ecff09ba9d2294e34757f8a6348d5 100644 (file)
@@ -354,24 +354,7 @@ command_set_config(DBus::Connection* conn, Snapper* snapper)
        exit(EXIT_FAILURE);
     }
 
-    map<string, string> 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<string, string> raw = read_configdata(getopts.getArgs());
 
     if (no_dbus)
     {
index 4725fe26dbf9c6ef6470ed981cdce3d2727fc1ec..78154af6d7ff8df72e66e1841cff6c402ae7db5d 100644 (file)
@@ -2,6 +2,7 @@
 #include <getopt.h>
 #include <string>
 #include <map>
+#include <list>
 
 
 class GetOpts
@@ -24,6 +25,10 @@ public:
 
     const char* popArg() { return argv[optind++]; }
 
+    std::list<std::string> getArgs() const {
+       return std::list<std::string>(&argv[optind], &argv[argc]);
+    }
+
 private:
 
     int argc;