From 24835e9933ee1dc26876eb4e33adb4769520ddc3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Feb 2024 11:45:33 +0100 Subject: [PATCH] varlinkctl: if "call" verb is used, imply "-j" For the other verbs turning off JSON mode makes sense, but for "call" not so much, after all the contents of a method call reply is JSON we couldn't really show any other way. Hence, when JSON output was not configured otherwise in "call", default to the same as -j. --- src/varlinkctl/varlinkctl.c | 8 +++++++- test/units/testsuite-54.sh | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index 714396d3874..26b764aca69 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -379,7 +379,13 @@ static int verb_call(int argc, char *argv[], void *userdata) { method = argv[2]; parameter = argc > 3 && !streq(argv[3], "-") ? argv[3] : NULL; - arg_json_format_flags &= ~JSON_FORMAT_OFF; + /* No JSON mode explicitly configured? Then default to the same as -j */ + if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) + arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO; + + /* For pipeable text tools it's kinda customary to finish output off in a newline character, and not + * leave incomplete lines hanging around. */ + arg_json_format_flags |= JSON_FORMAT_NEWLINE; if (parameter) { /* is correct, as dispatch_verb() shifts arguments by one for the verb. */ diff --git a/test/units/testsuite-54.sh b/test/units/testsuite-54.sh index 8f20ac43286..7618e92c9fa 100755 --- a/test/units/testsuite-54.sh +++ b/test/units/testsuite-54.sh @@ -348,10 +348,10 @@ fi # Decrypt/encrypt via varlink -echo -n '{"data":"Zm9vYmFyCg=="}' > /tmp/vlcredsdata +echo '{"data":"Zm9vYmFyCg=="}' > /tmp/vlcredsdata varlinkctl call /run/systemd/io.systemd.Credentials io.systemd.Credentials.Encrypt "$(cat /tmp/vlcredsdata)" | \ - varlinkctl call /run/systemd/io.systemd.Credentials io.systemd.Credentials.Decrypt > /tmp/vlcredsdata2 + varlinkctl call --json=short /run/systemd/io.systemd.Credentials io.systemd.Credentials.Decrypt > /tmp/vlcredsdata2 cmp /tmp/vlcredsdata /tmp/vlcredsdata2 rm /tmp/vlcredsdata /tmp/vlcredsdata2 -- 2.47.3