From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f67.google.com ([209.85.215.67]:34100 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932171AbeBSWZF (ORCPT ); Mon, 19 Feb 2018 17:25:05 -0500 Received: by mail-lf0-f67.google.com with SMTP id l191so1559293lfe.1 for ; Mon, 19 Feb 2018 14:25:04 -0800 (PST) Subject: Re: [PATCH iproute2-next 1/4] bridge: implement json pretty print flag To: Stephen Hemminger , netdev@vger.kernel.org References: <20180219031818.25797-1-stephen@networkplumber.org> <20180219031818.25797-2-stephen@networkplumber.org> From: Serhey Popovych Message-ID: <86ffe1d0-a82c-26d7-3144-b9116f5d211e@gmail.com> Date: Tue, 20 Feb 2018 00:24:46 +0200 MIME-Version: 1.0 In-Reply-To: <20180219031818.25797-2-stephen@networkplumber.org> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3so3xdXUKRl86XdCAAvAfyUjhszHZYbt3" Sender: netdev-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --3so3xdXUKRl86XdCAAvAfyUjhszHZYbt3 Content-Type: multipart/mixed; boundary="yFEiKqYww9W56L0skZoQW9xz86ZCRBJ0Y"; protected-headers="v1" From: Serhey Popovych To: Stephen Hemminger , netdev@vger.kernel.org Message-ID: <86ffe1d0-a82c-26d7-3144-b9116f5d211e@gmail.com> Subject: Re: [PATCH iproute2-next 1/4] bridge: implement json pretty print flag References: <20180219031818.25797-1-stephen@networkplumber.org> <20180219031818.25797-2-stephen@networkplumber.org> In-Reply-To: <20180219031818.25797-2-stephen@networkplumber.org> --yFEiKqYww9W56L0skZoQW9xz86ZCRBJ0Y Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Stephen Hemminger wrote: > Make bridge work like other iproute2 commands with standard -j and -p > flags. >=20 > Signed-off-by: Stephen Hemminger > --- > bridge/br_common.h | 3 ++- > bridge/bridge.c | 9 ++++++--- > bridge/fdb.c | 10 ++++++---- > bridge/mdb.c | 12 ++++++++++-- > bridge/vlan.c | 11 +++++++---- > man/man8/bridge.8 | 6 ++++++ > 6 files changed, 37 insertions(+), 14 deletions(-) >=20 > diff --git a/bridge/br_common.h b/bridge/br_common.h > index f07c7d1c9090..32dc46a2415d 100644 > --- a/bridge/br_common.h > +++ b/bridge/br_common.h > @@ -24,7 +24,8 @@ extern int do_link(int argc, char **argv); > extern int preferred_family; > extern int show_stats; > extern int show_details; > +extern int show_pretty; Why not to use @pretty from utils.c/utils.h recently added as common point for json_print.c and rest of the code with commit 543365670534 ("ip: Use single variable to represent -pretty")? While new_json_obj() from json_print.c isn't used in bridge/ it is still seems reasonable in my opinion to use common @pretty variable. > extern int timestamp; > extern int compress_vlans; > -extern int json_output; > +extern int json; > extern struct rtnl_handle rth; > diff --git a/bridge/bridge.c b/bridge/bridge.c > index 48fe1c8b2ef1..3837c3d79290 100644 > --- a/bridge/bridge.c > +++ b/bridge/bridge.c > @@ -22,8 +22,9 @@ int preferred_family =3D AF_UNSPEC; > int oneline; > int show_stats; > int show_details; > +int show_pretty; > int compress_vlans; > -int json_output; > +int json; > int timestamp; > char *batch_file; > int force; > @@ -39,7 +40,7 @@ static void usage(void) > "where OBJECT :=3D { link | fdb | mdb | vlan | monitor }\n" > " OPTIONS :=3D { -V[ersion] | -s[tatistics] | -d[etails] |\n" > " -o[neline] | -t[imestamp] | -n[etns] name |\n" > -" -c[ompressvlans] -j{son} }\n"); > +" -c[ompressvlans] -p[retty] -j{son} }\n"); > exit(-1); > } > =20 > @@ -175,7 +176,9 @@ main(int argc, char **argv) > } else if (matches(opt, "-force") =3D=3D 0) { > ++force; > } else if (matches(opt, "-json") =3D=3D 0) { > - ++json_output; > + ++json; > + } else if (matches(opt, "-pretty") =3D=3D 0) { > + ++show_pretty; > } else if (matches(opt, "-batch") =3D=3D 0) { > argc--; > argv++; > diff --git a/bridge/fdb.c b/bridge/fdb.c > index 8b133f9c1c8d..82dff5167e86 100644 > --- a/bridge/fdb.c > +++ b/bridge/fdb.c > @@ -132,10 +132,8 @@ int print_fdb(const struct sockaddr_nl *who, struc= t nlmsghdr *n, void *arg) > if (filter_vlan && filter_vlan !=3D vid) > return 0; > =20 > - if (jw_global) { > - jsonw_pretty(jw_global, 1); > + if (jw_global) > jsonw_start_object(jw_global); > - } > =20 > if (n->nlmsg_type =3D=3D RTM_DELNEIGH) { > if (jw_global) > @@ -388,14 +386,18 @@ static int fdb_show(int argc, char **argv) > exit(1); > } > =20 > - if (json_output) { > + if (json) { > jw_global =3D jsonw_new(stdout); > if (!jw_global) { > fprintf(stderr, "Error allocation json object\n"); > exit(1); > } > + if (show_pretty) > + jsonw_pretty(jw_global, 1); > + > jsonw_start_array(jw_global); > } > + > if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) { > fprintf(stderr, "Dump terminated\n"); > exit(1); > diff --git a/bridge/mdb.c b/bridge/mdb.c > index 62dc8a0c58c3..0873502e8a24 100644 > --- a/bridge/mdb.c > +++ b/bridge/mdb.c > @@ -325,7 +325,7 @@ static int mdb_show(int argc, char **argv) > return -1; > } > =20 > - if (!json_output) { > + if (!json) { > /* Normal output */ > if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) { > fprintf(stderr, "Dump terminated\n"); > @@ -333,9 +333,17 @@ static int mdb_show(int argc, char **argv) > } > return 0; > } > + > /* Json output */ > jw_global =3D jsonw_new(stdout); > - jsonw_pretty(jw_global, 1); > + if (!jw_global) { > + fprintf(stderr, "Error allocation json object\n"); > + exit(1); > + } > + > + if (show_pretty) > + jsonw_pretty(jw_global, 1); > + > jsonw_start_object(jw_global); > jsonw_name(jw_global, "mdb"); > jsonw_start_array(jw_global); > diff --git a/bridge/vlan.c b/bridge/vlan.c > index f42d7e6ba244..e4eab4c2384f 100644 > --- a/bridge/vlan.c > +++ b/bridge/vlan.c > @@ -258,7 +258,6 @@ static int filter_vlan_check(__u16 vid, __u16 flags= ) > static void print_vlan_port(FILE *fp, int ifi_index) > { > if (jw_global) { > - jsonw_pretty(jw_global, 1); > jsonw_name(jw_global, > ll_index_to_name(ifi_index)); > jsonw_start_array(jw_global); > @@ -578,17 +577,21 @@ static int vlan_show(int argc, char **argv) > if (!show_stats) { > if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK, > (compress_vlans ? > - RTEXT_FILTER_BRVLAN_COMPRESSED : > - RTEXT_FILTER_BRVLAN)) < 0) { > + RTEXT_FILTER_BRVLAN_COMPRESSED : > + RTEXT_FILTER_BRVLAN)) < 0) { > perror("Cannont send dump request"); > exit(1); > } > - if (json_output) { > + > + if (json) { > jw_global =3D jsonw_new(stdout); > if (!jw_global) { > fprintf(stderr, "Error allocation json object\n"); > exit(1); > } > + if (show_pretty) > + jsonw_pretty(jw_global, 1); > + > jsonw_start_object(jw_global); > } else { > if (show_vlan_tunnel_info) > diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 > index d6baa819020a..490ef58da16c 100644 > --- a/man/man8/bridge.8 > +++ b/man/man8/bridge.8 > @@ -22,6 +22,7 @@ bridge \- show / manipulate bridge addresses and devi= ces > \fB\-s\fR[\fItatistics\fR] | > \fB\-n\fR[\fIetns\fR] name | > \fB\-b\fR[\fIatch\fR] filename | > +\fB\-p\fR[\fIretty\fR] | > \fB\-j\fR[\fIson\fR] } > =20 > .ti -8 > @@ -171,6 +172,11 @@ return code will be non zero. > .BR "\-json" > Display results in JSON format. Currently available for vlan and fdb. > =20 > +.TP > +.BR "\-pretty" > +When combined with -j generate a pretty JSON output. > + > + > .SH BRIDGE - COMMAND SYNTAX > =20 > .SS >=20 --yFEiKqYww9W56L0skZoQW9xz86ZCRBJ0Y-- --3so3xdXUKRl86XdCAAvAfyUjhszHZYbt3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJai069AAoJEBTawMmQ61bBb3UIALiAwqWRYcJZ1BQoqfo+PTO1 fFPxqHE3AZRyil5cVfUaFCH4+yUkCDywrAAlBLWo1qvHT8PqZoxKFBwqNN3gbeF0 nJsD2AK0im2YwcntGW6aAhwqF52/eXE2UIJPVB0Hrx/Cvh+O8ki9obQISCRNXlng rPN8exZynGo+OgWw12BgQIpfw3KP3a3IWO7SK6eqmwA0jUrIjuQ/D6tfKkK2hhW2 Ksl2k8JO1zMm0JDLP0zdvPLCcr/TM0ybRFpvwmdMrkF/tRNvYpc8CMrIwl3OJJbE YySfHlWZXRJDucIDMsfmICkF13SEFQoFEuliZfUGBUgdd0a67zqS+Mn78BxWdyI= =tN4L -----END PGP SIGNATURE----- --3so3xdXUKRl86XdCAAvAfyUjhszHZYbt3--