]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add JSON support to sample application
authorKarel Zak <kzak@redhat.com>
Fri, 16 Sep 2016 11:30:29 +0000 (13:30 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Sep 2016 11:30:29 +0000 (13:30 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/samples/fromfile.c

index 7ad6d742c8465ec9e76c8201acb5f4a685ca97b8..e33cb3c9aaf1153d1225462f2c12ec28c1ccd88e 100644 (file)
@@ -194,6 +194,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(" -m, --maxout                   fill all terminal width\n", out);
        fputs(" -c, --column <file>            column definition\n", out);
        fputs(" -n, --nlines <num>             number of lines\n", out);
+       fputs(" -J, --json                     JSON output format\n", out);
        fputs(" -w, --width <num>              hardcode terminal width\n", out);
        fputs(" -p, --tree-parent-column <n>   parent column\n", out);
        fputs(" -i, --tree-id-column <n>       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;