]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/parse-argument.c
run: also show a pretty string for main exit status, if any
[thirdparty/systemd.git] / src / shared / parse-argument.c
index cd1d0dde21a54cbbe0b0074ab2a504f3a23c3db6..145bd119ac7a2cc7d2241a9c909e5bb15ac1d824 100644 (file)
@@ -8,7 +8,28 @@
 #include "string-table.h"
 #include "string-util.h"
 
-/* All functions in this file emit warnigs. */
+/* All functions in this file emit warnings. */
+
+int parse_boolean_argument(const char *optname, const char *s, bool *ret) {
+        int r;
+
+        /* Returns the result through *ret and the return value. */
+
+        if (s) {
+                r = parse_boolean(s);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse boolean argument to %s: %s.", optname, s);
+
+                if (ret)
+                        *ret = r;
+                return r;
+        } else {
+                /* s may be NULL. This is controlled by getopt_long() parameters. */
+                if (ret)
+                        *ret = true;
+                return true;
+        }
+}
 
 int parse_json_argument(const char *s, JsonFormatFlags *ret) {
         assert(s);
@@ -52,7 +73,7 @@ int parse_path_argument(const char *path, bool suppress_root, char **arg) {
         if (r < 0)
                 return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
 
-        path_simplify(p, false);
+        path_simplify(p);
         if (suppress_root && empty_or_root(p))
                 p = mfree(p);