diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-08 10:40:10 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-13 11:30:52 +0200 |
commit | cd4e9166bb5f0b970367c54e198817f94213a376 (patch) | |
tree | 1bd90a7fec55941d9fd72bc14dbbe02a7f615cc1 /src/varlinkctl | |
parent | json: move empty string check from json_parse_file_at() to json_parse_with_so... (diff) | |
download | systemd-cd4e9166bb5f0b970367c54e198817f94213a376.tar.xz systemd-cd4e9166bb5f0b970367c54e198817f94213a376.zip |
varlinkctl: add "-q" switch for suppressing varlinkctl output
Diffstat (limited to 'src/varlinkctl')
-rw-r--r-- | src/varlinkctl/varlinkctl.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index 739770d296..676fb93054 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -21,6 +21,7 @@ static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF; static PagerFlags arg_pager_flags = 0; static VarlinkMethodFlags arg_method_flags = 0; static bool arg_collect = false; +static bool arg_quiet = false; static int help(void) { _cleanup_free_ char *link = NULL; @@ -56,6 +57,7 @@ static int help(void) { " --oneway Do not request response\n" " --json=MODE Output as JSON\n" " -j Same as --json=pretty on tty, --json=short otherwise\n" + " -q --quiet Do not output method reply\n" "\nSee the %2$s for details.\n", program_invocation_short_name, link, @@ -90,6 +92,7 @@ static int parse_argv(int argc, char *argv[]) { { "oneway", no_argument, NULL, ARG_ONEWAY }, { "json", required_argument, NULL, ARG_JSON }, { "collect", no_argument, NULL, ARG_COLLECT }, + { "quiet", no_argument, NULL, 'q' }, {}, }; @@ -98,7 +101,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hj", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "hjq", options, NULL)) >= 0) switch (c) { @@ -135,6 +138,10 @@ static int parse_argv(int argc, char *argv[]) { arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO; break; + case 'q': + arg_quiet = true; + break; + case '?': return -EINVAL; @@ -435,7 +442,9 @@ static int reply_callback( } else r = 0; - sd_json_variant_dump(parameters, arg_json_format_flags, stdout, NULL); + if (!arg_quiet) + sd_json_variant_dump(parameters, arg_json_format_flags, stdout, NULL); + return r; } @@ -490,6 +499,9 @@ static int verb_call(int argc, char *argv[], void *userdata) { } else r = 0; + if (arg_quiet) + return r; + pager_open(arg_pager_flags); sd_json_variant_dump(reply, arg_json_format_flags, stdout, NULL); return r; @@ -552,6 +564,9 @@ static int verb_call(int argc, char *argv[], void *userdata) { } else r = 0; + if (arg_quiet) + return r; + pager_open(arg_pager_flags); sd_json_variant_dump(reply, arg_json_format_flags, stdout, NULL); @@ -598,6 +613,9 @@ static int verb_validate_idl(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to check interface for consistency: %m"); + if (arg_quiet) + return 0; + pager_open(arg_pager_flags); r = varlink_idl_dump(stdout, /* use_colors= */ -1, vi); |