This adds a new flag JSON_FORMAT_OFF that is a marker for "no JSON
output please!".
Of course, this flag sounds pointless in a JSON implementation, however
this is useful in code that can generate JSON output, but also more
human friendly output (for example our table formatters).
With this in place various tools that so far maintained one boolean
field "arg_json" that controlled whether JSON output was requested at
all and another field "arg_json_format_flags" for selecing the precise
json output flags may merge them into one, simplifying code a bit.
assert(t);
+ if (flags & JSON_FORMAT_OFF) /* If JSON output is turned off, use regular output */
+ return table_print(t, f);
+
if (!f)
f = stdout;
assert_return(v, -EINVAL);
assert_return(ret, -EINVAL);
+ if (flags & JSON_FORMAT_OFF)
+ return -ENOEXEC;
+
{
_cleanup_fclose_ FILE *f = NULL;
JSON_FORMAT_SSE = 1 << 6, /* prefix/suffix with W3C server-sent events */
JSON_FORMAT_SEQ = 1 << 7, /* prefix/suffix with RFC 7464 application/json-seq */
JSON_FORMAT_FLUSH = 1 << 8, /* call fflush() after dumping JSON */
+ JSON_FORMAT_OFF = 1 << 9, /* make json_variant_format() fail with -ENOEXEC */
} JsonFormatFlags;
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);