mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-08-14 13:17:42 +00:00
json: make pretty printing optional
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> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
db2b8b6ef0
commit
a233caa0aa
@ -15,6 +15,8 @@
|
|||||||
#include "json_writer.h"
|
#include "json_writer.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
|
||||||
|
extern int show_pretty;
|
||||||
|
|
||||||
json_writer_t *get_json_writer(void);
|
json_writer_t *get_json_writer(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
3
ip/ip.c
3
ip/ip.c
@ -31,6 +31,7 @@ int show_stats;
|
|||||||
int show_details;
|
int show_details;
|
||||||
int oneline;
|
int oneline;
|
||||||
int brief;
|
int brief;
|
||||||
|
int show_pretty;
|
||||||
int json;
|
int json;
|
||||||
int timestamp;
|
int timestamp;
|
||||||
const char *_SL_;
|
const char *_SL_;
|
||||||
@ -259,6 +260,8 @@ int main(int argc, char **argv)
|
|||||||
++brief;
|
++brief;
|
||||||
} else if (matches(opt, "-json") == 0) {
|
} else if (matches(opt, "-json") == 0) {
|
||||||
++json;
|
++json;
|
||||||
|
} else if (matches(opt, "-pretty") == 0) {
|
||||||
|
++show_pretty;
|
||||||
} else if (matches(opt, "-rcvbuf") == 0) {
|
} else if (matches(opt, "-rcvbuf") == 0) {
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ void new_json_obj(int json)
|
|||||||
perror("json object");
|
perror("json object");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
jsonw_pretty(_jw, true);
|
if (show_pretty)
|
||||||
|
jsonw_pretty(_jw, true);
|
||||||
jsonw_start_array(_jw);
|
jsonw_start_array(_jw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
tc/tc.c
3
tc/tc.c
@ -42,6 +42,7 @@ int use_iec;
|
|||||||
int force;
|
int force;
|
||||||
bool use_names;
|
bool use_names;
|
||||||
int json;
|
int json;
|
||||||
|
int pretty;
|
||||||
|
|
||||||
static char *conf_file;
|
static char *conf_file;
|
||||||
|
|
||||||
@ -484,6 +485,8 @@ int main(int argc, char **argv)
|
|||||||
++timestamp_short;
|
++timestamp_short;
|
||||||
} else if (matches(argv[1], "-json") == 0) {
|
} else if (matches(argv[1], "-json") == 0) {
|
||||||
++json;
|
++json;
|
||||||
|
} else if (matches(argv[1], "-pretty") == 0) {
|
||||||
|
++pretty;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user