From 6f2737964d57b55994ff59237903737dde7e8bdd Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 22 Jan 2016 13:46:29 +0100 Subject: [PATCH] libsmartcols: add JSON to the test application Signed-off-by: Karel Zak --- libsmartcols/src/test.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c index dd87fd38b..5b2cc6433 100644 --- a/libsmartcols/src/test.c +++ b/libsmartcols/src/test.c @@ -147,6 +147,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(" -l, --list use list format output\n", out); fputs(" -n, --noheadings don't print headings\n", out); fputs(" -p, --pairs use key=\"value\" output format\n", out); + fputs(" -J, --json use JSON output format\n", out); fputs(" -r, --raw use raw output format\n", out); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); @@ -163,7 +164,8 @@ int main(int argc, char *argv[]) { "list", 0, 0, 'l' }, { "noheadings", 0, 0, 'n' }, { "pairs", 0, 0, 'p' }, - { "raw", 0, 0, 'r' }, + { "json", 0, 0, 'J' }, + { "raw", 0, 0, 'r' }, { NULL, 0, 0, 0 }, }; @@ -176,7 +178,7 @@ int main(int argc, char *argv[]) if (!tb) err(EXIT_FAILURE, "faild to create output table"); - while((c = getopt_long(argc, argv, "cilnpr", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "ciJlnpr", longopts, NULL)) != -1) { switch(c) { case 'c': scols_table_set_column_separator(tb, ","); @@ -186,6 +188,10 @@ int main(int argc, char *argv[]) case 'i': scols_table_enable_ascii(tb, 1); break; + case 'J': + scols_table_set_name(tb, "scolstest"); + scols_table_enable_json(tb, 1); + break; case 'l': notree = 1; break;