summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-14 11:45:01 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-15 08:50:45 +0100
commitb1e8f46c318d88df8e0939e6cf2428ba4c343957 (patch)
tree89c247b1baca24664887a77b9ce55d04ec38887a
parentMove and rename parse_path_argument() function (diff)
downloadsystemd-b1e8f46c318d88df8e0939e6cf2428ba4c343957.tar.xz
systemd-b1e8f46c318d88df8e0939e6cf2428ba4c343957.zip
Move and rename parse_json_argument() function
json.[ch] is a very generic implementation, and cmdline argument parsing doesn't fit there.
-rw-r--r--src/busctl/busctl.c3
-rw-r--r--src/coredump/coredumpctl.c3
-rw-r--r--src/dissect/dissect.c2
-rw-r--r--src/home/homectl.c2
-rw-r--r--src/partition/repart.c2
-rw-r--r--src/shared/json.c21
-rw-r--r--src/shared/json.h2
-rw-r--r--src/shared/parse-argument.c21
-rw-r--r--src/shared/parse-argument.h3
-rw-r--r--src/sysext/sysext.c2
10 files changed, 32 insertions, 29 deletions
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 7774aeac7c..6a492ebd02 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -21,6 +21,7 @@
#include "log.h"
#include "main-func.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
@@ -2523,7 +2524,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 46183451de..20cd90bd56 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -25,6 +25,7 @@
#include "macro.h"
#include "main-func.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
@@ -320,7 +321,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index e5ca85ffc5..f8f34dcc4d 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -260,7 +260,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;
diff --git a/src/home/homectl.c b/src/home/homectl.c
index c667419a51..83fc86efe3 100644
--- a/src/home/homectl.c
+++ b/src/home/homectl.c
@@ -3234,7 +3234,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 9828085018..78c31187ea 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -3688,7 +3688,7 @@ static int parse_argv(int argc, char *argv[]) {
}
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;
diff --git a/src/shared/json.c b/src/shared/json.c
index b8f8292e74..cc79375410 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -4459,27 +4459,6 @@ int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size) {
return unhexmem(json_variant_string(v), (size_t) -1, ret, ret_size);
}
-int json_parse_cmdline_parameter_and_warn(const char *s, JsonFormatFlags *ret) {
- assert(s);
- assert(ret);
-
- if (streq(s, "pretty"))
- *ret = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO;
- else if (streq(s, "short"))
- *ret = JSON_FORMAT_NEWLINE;
- else if (streq(s, "off"))
- *ret = JSON_FORMAT_OFF;
- else if (streq(s, "help")) {
- puts("pretty\n"
- "short\n"
- "off");
- return 0; /* 0 means → we showed a brief help, exit now */
- } else
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json= switch: %s", s);
-
- return 1; /* 1 means → properly parsed */
-}
-
static const char* const json_variant_type_table[_JSON_VARIANT_TYPE_MAX] = {
[JSON_VARIANT_STRING] = "string",
[JSON_VARIANT_INTEGER] = "integer",
diff --git a/src/shared/json.h b/src/shared/json.h
index a335dd3623..d429066761 100644
--- a/src/shared/json.h
+++ b/src/shared/json.h
@@ -357,7 +357,5 @@ int json_log_internal(JsonVariant *variant, int level, int error, const char *fi
int json_variant_unbase64(JsonVariant *v, void **ret, size_t *ret_size);
int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size);
-int json_parse_cmdline_parameter_and_warn(const char *s, JsonFormatFlags *ret);
-
const char *json_variant_type_to_string(JsonVariantType t);
JsonVariantType json_variant_type_from_string(const char *s);
diff --git a/src/shared/parse-argument.c b/src/shared/parse-argument.c
index 774cb1bc82..cd1d0dde21 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_json_argument(const char *s, JsonFormatFlags *ret) {
+ assert(s);
+ assert(ret);
+
+ if (streq(s, "pretty"))
+ *ret = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO;
+ else if (streq(s, "short"))
+ *ret = JSON_FORMAT_NEWLINE;
+ else if (streq(s, "off"))
+ *ret = JSON_FORMAT_OFF;
+ else if (streq(s, "help")) {
+ puts("pretty\n"
+ "short\n"
+ "off");
+ return 0; /* 0 means → we showed a brief help, exit now */
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json= switch: %s", s);
+
+ return 1; /* 1 means → properly parsed */
+}
+
int parse_path_argument(const char *path, bool suppress_root, char **arg) {
char *p;
int r;
diff --git a/src/shared/parse-argument.h b/src/shared/parse-argument.h
index 4ec334fe5e..28b58cc2e2 100644
--- a/src/shared/parse-argument.h
+++ b/src/shared/parse-argument.h
@@ -1,5 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include "json.h"
+
+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);
diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c
index ff8d58902a..57a36d478a 100644
--- a/src/sysext/sysext.c
+++ b/src/sysext/sysext.c
@@ -950,7 +950,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_JSON:
- r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
+ r = parse_json_argument(optarg, &arg_json_format_flags);
if (r <= 0)
return r;