diff mbox series

[ndctl,15/37] util/json: Warn on stderr about empty list results

Message ID 164298558814.3021641.13051269428355986099.stgit@dwillia2-desk3.amr.corp.intel.com
State New, archived
Headers show
Series cxl: Full topology enumeration | expand

Commit Message

Dan Williams Jan. 24, 2022, 12:53 a.m. UTC
Help interactive users notice something is wrong with the list parameters
by warning that no devices matched the specified filter settings.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/json.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/util/json.c b/util/json.c
index bd5f8fc47a2b..f8cc81f6e706 100644
--- a/util/json.c
+++ b/util/json.c
@@ -3,6 +3,7 @@ 
 #include <limits.h>
 #include <string.h>
 #include <stdio.h>
+#include <util/util.h>
 #include <util/json.h>
 #include <json-c/json.h>
 #include <json-c/printbuf.h>
@@ -95,9 +96,11 @@  void util_display_json_array(FILE *f_out, struct json_object *jarray,
 	int len = json_object_array_length(jarray);
 	int jflag = JSON_C_TO_STRING_PRETTY;
 
-	if (json_object_array_length(jarray) > 1 || !(flags & UTIL_JSON_HUMAN))
+	if (len > 1 || !(flags & UTIL_JSON_HUMAN)) {
+		if (len == 0)
+			warning("no matching devices found\n");
 		fprintf(f_out, "%s\n", json_object_to_json_string_ext(jarray, jflag));
-	else if (len) {
+	} else if (len) {
 		struct json_object *jobj;
 
 		jobj = json_object_array_get_idx(jarray, 0);