From 6a82714dbfa7b3a73b972e015e6ca3d91514eddb Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 16 Sep 2016 13:30:29 +0200 Subject: libsmartcols: add JSON support to sample application Signed-off-by: Karel Zak --- libsmartcols/samples/fromfile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libsmartcols/samples') diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c index 7ad6d742c..e33cb3c9a 100644 --- a/libsmartcols/samples/fromfile.c +++ b/libsmartcols/samples/fromfile.c @@ -194,6 +194,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fputs(" -m, --maxout fill all terminal width\n", out); fputs(" -c, --column column definition\n", out); fputs(" -n, --nlines number of lines\n", out); + fputs(" -J, --json JSON output format\n", out); fputs(" -w, --width hardcode terminal width\n", out); fputs(" -p, --tree-parent-column parent column\n", out); fputs(" -i, --tree-id-column id column\n", out); @@ -216,6 +217,7 @@ int main(int argc, char *argv[]) { "width", 1, 0, 'w' }, { "tree-parent-column", 1, 0, 'p' }, { "tree-id-column", 1, 0, 'i' }, + { "json", 0, 0, 'J' }, { "help", 0, 0, 'h' }, { NULL, 0, 0, 0 }, }; @@ -228,7 +230,7 @@ int main(int argc, char *argv[]) if (!tb) err(EXIT_FAILURE, "failed to create output table"); - while((c = getopt_long(argc, argv, "hc:i:mn:p:w:", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "hc:i:Jmn:p:w:", longopts, NULL)) != -1) { switch(c) { case 'c': /* add column from file */ { @@ -250,6 +252,10 @@ int main(int argc, char *argv[]) case 'i': id_col = strtou32_or_err(optarg, "failed to parse tree ID column"); break; + case 'J': + scols_table_enable_json(tb, 1); + scols_table_set_name(tb, "testtable"); + break; case 'm': scols_table_enable_maxout(tb, TRUE); break; -- cgit v1.2.3-55-g7522