summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-17 23:40:04 +0100
committerGitHub <noreply@github.com>2021-02-17 23:40:04 +0100
commitdc288ffeabebd72a686dbd530e2aa169472f7fe4 (patch)
tree679d9dcd235e0e19408deb2be99b195dea618212 /src/shared
parentMerge pull request #18651 from poettering/einval-followup (diff)
parentshell-completion: complete --legend=no for resolvectl and systemctl (diff)
downloadsystemd-dc288ffeabebd72a686dbd530e2aa169472f7fe4.tar.xz
systemd-dc288ffeabebd72a686dbd530e2aa169472f7fe4.zip
Merge pull request #18596 from keszybz/systemctl-quiet-legend
systemctl: hide legends with --quiet, allow overriding
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/parse-argument.c21
-rw-r--r--src/shared/parse-argument.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/parse-argument.c b/src/shared/parse-argument.c
index cd1d0dde21..db182e4bcb 100644
--- a/src/shared/parse-argument.c
+++ b/src/shared/parse-argument.c
@@ -10,6 +10,27 @@
/* All functions in this file emit warnigs. */
+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);
assert(ret);
diff --git a/src/shared/parse-argument.h b/src/shared/parse-argument.h
index 28b58cc2e2..adad65e902 100644
--- a/src/shared/parse-argument.h
+++ b/src/shared/parse-argument.h
@@ -3,6 +3,7 @@
#include "json.h"
+int parse_boolean_argument(const char *optname, const char *s, bool *ret);
int parse_json_argument(const char *s, JsonFormatFlags *ret);
int parse_path_argument(const char *path, bool suppress_root, char **arg);
int parse_signal_argument(const char *s, int *ret);