All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dsahern@gmail.com
Cc: netdev@vger.kernel.org,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC iproute2-next 14/16] json: make pretty printing optional
Date: Thu,  1 Feb 2018 17:19:44 -0800	[thread overview]
Message-ID: <20180202011946.21929-15-sthemmin@microsoft.com> (raw)
In-Reply-To: <20180202011946.21929-1-sthemmin@microsoft.com>

Since JSON is intended for programmatic consumption, it makes
sense for the default output format to be concise as possible.

For programmer and other uses, it is helpful to keep the pretty
whitespace format; therefore enable it with -p flag.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 include/json_print.h | 2 ++
 include/utils.h      | 1 -
 ip/ip.c              | 3 +++
 lib/json_print.c     | 3 ++-
 tc/tc.c              | 3 +++
 5 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/json_print.h b/include/json_print.h
index 2ca7830adbd6..45a817ce6b9a 100644
--- a/include/json_print.h
+++ b/include/json_print.h
@@ -15,6 +15,8 @@
 #include "json_writer.h"
 #include "color.h"
 
+extern int show_pretty;
+
 json_writer_t *get_json_writer(void);
 
 /*
diff --git a/include/utils.h b/include/utils.h
index 27ba37c5cd2f..e35ea32c1d3b 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -23,7 +23,6 @@ extern int resolve_hosts;
 extern int oneline;
 extern int brief;
 extern int json;
-extern int pretty;
 extern int timestamp;
 extern int timestamp_short;
 extern const char * _SL_;
diff --git a/ip/ip.c b/ip/ip.c
index b15e6b66b3f6..a6611292808d 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -31,6 +31,7 @@ int show_stats;
 int show_details;
 int oneline;
 int brief;
+int show_pretty;
 int json;
 int timestamp;
 const char *_SL_;
@@ -259,6 +260,8 @@ int main(int argc, char **argv)
 			++brief;
 		} else if (matches(opt, "-json") == 0) {
 			++json;
+		} else if (matches(opt, "-pretty") == 0) {
+			++show_pretty;
 		} else if (matches(opt, "-rcvbuf") == 0) {
 			unsigned int size;
 
diff --git a/lib/json_print.c b/lib/json_print.c
index 6518ba98f5bf..e3da1bdfd5b0 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -28,7 +28,8 @@ void new_json_obj(int json)
 			perror("json object");
 			exit(1);
 		}
-		jsonw_pretty(_jw, true);
+		if (show_pretty)
+			jsonw_pretty(_jw, true);
 		jsonw_start_array(_jw);
 	}
 }
diff --git a/tc/tc.c b/tc/tc.c
index 63e64fece87d..aba5c101739c 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -42,6 +42,7 @@ int use_iec;
 int force;
 bool use_names;
 int json;
+int pretty;
 
 static char *conf_file;
 
@@ -484,6 +485,8 @@ int main(int argc, char **argv)
 			++timestamp_short;
 		} else if (matches(argv[1], "-json") == 0) {
 			++json;
+		} else if (matches(argv[1], "-pretty") == 0) {
+			++pretty;
 		} else {
 			fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
 			return -1;
-- 
2.15.1

  parent reply	other threads:[~2018-02-02  1:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02  1:19 [RFC iproute2-next 00/16] iproute printing enhancements Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 01/16] iproute: refactor printing flags Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 02/16] iproute: make printing icmpv6 a function Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 03/16] iproute: make printing IPv4 cache flags " Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 04/16] iproute: refactor cacheinfo printing Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 05/16] iproute: refactor metrics print Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 06/16] iproute: refactor printing flow info Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 07/16] iproute2: refactor newdst, gateway and via printing Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 08/16] iproute: refactor multipath print Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 09/16] iproute: refactor printing of interface Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 10/16] iproute: whitespace fixes Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 11/16] iproute: don't do assignment in condition Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 12/16] iproute: make flush a separate function Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 13/16] iproute: implement JSON and color output Stephen Hemminger
2018-02-02  1:19 ` Stephen Hemminger [this message]
2018-02-02  1:19 ` [RFC iproute2-next 15/16] man: add documentation for json and pretty flags Stephen Hemminger
2018-02-02  1:19 ` [RFC iproute2-next 16/16] json: fix newline at end of array Stephen Hemminger
2018-02-02  2:59 ` [RFC iproute2-next 00/16] iproute printing enhancements David Ahern
2018-02-02  3:08 ` David Ahern
2018-02-02 22:24   ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180202011946.21929-15-sthemmin@microsoft.com \
    --to=stephen@networkplumber.org \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.