bootctl: use output mode where "[]" is written instead for empty output
It's easier for the caller if output is always a list, even if there are no entries.
This commit is contained in:
@@ -1448,7 +1448,7 @@ int show_boot_entries(const BootConfig *config, JsonFormatFlags json_format) {
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
json_variant_dump(array, json_format, NULL, NULL);
|
||||
json_variant_dump(array, json_format | JSON_FORMAT_EMPTY_ARRAY, NULL, NULL);
|
||||
|
||||
} else {
|
||||
for (size_t n = 0; n < config->n_entries; n++) {
|
||||
|
||||
+6
-2
@@ -1810,8 +1810,12 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
|
||||
}
|
||||
|
||||
int json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const char *prefix) {
|
||||
if (!v)
|
||||
return 0;
|
||||
if (!v) {
|
||||
if (flags & JSON_FORMAT_EMPTY_ARRAY)
|
||||
v = JSON_VARIANT_MAGIC_EMPTY_ARRAY;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!f)
|
||||
f = stdout;
|
||||
|
||||
+2
-1
@@ -194,7 +194,8 @@ typedef enum JsonFormatFlags {
|
||||
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 */
|
||||
JSON_FORMAT_EMPTY_ARRAY = 1 << 9, /* output "[]" for empty input */
|
||||
JSON_FORMAT_OFF = 1 << 10, /* make json_variant_format() fail with -ENOEXEC */
|
||||
} JsonFormatFlags;
|
||||
|
||||
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);
|
||||
|
||||
Reference in New Issue
Block a user