]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fincore: add --raw and --json
authorKarel Zak <kzak@redhat.com>
Thu, 23 Mar 2017 13:34:12 +0000 (14:34 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Mar 2017 13:34:12 +0000 (14:34 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/fincore.1
misc-utils/fincore.c

index a615d6ab6955a73a33ab3d67db913a93a08591c1..942dd70d1551be87525c4aec1ab64da053b1ec24 100644 (file)
@@ -36,6 +36,13 @@ Define output columns.  See the \fB\-\-help\fP output to get a list of the
 currently supported columns. The default list of columns may be extended if \fIlist\fP is
 specified in the format \fI+list\fP.
 .TP
+.BR \-r , " \-\-raw"
+Produce output in raw format.  All potentially unsafe characters are hex-escaped
+(\\x<code>).
+.TP
+.BR \-J , " \-\-json"
+Use JSON output format.
+.TP
 \fB\-V\fR, \fB\-\-version\fR
 Display version information and exit.
 .TP
index 2d46fae39e7ef379c8b9c922d9de12b591631c08..ddb2bb267ccac98addfedf5e48eff016d16eec80 100644 (file)
@@ -71,7 +71,9 @@ struct fincore_control {
        struct libscols_table *tb;              /* output */
 
        unsigned int bytes : 1,
-                    noheadings : 1;
+                    noheadings : 1,
+                    raw : 1,
+                    json : 1;
 };
 
 
@@ -245,9 +247,11 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, out);
+       fputs(_(" -J, --json            use JSON output format\n"), out);
        fputs(_(" -b, --bytes           print sizes in bytes rather than in human readable format\n"), out);
        fputs(_(" -n, --noheadings      don't print headings\n"), out);
        fputs(_(" -o, --output <list>   output columns\n"), out);
+       fputs(_(" -r, --raw             use raw output format\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
        fputs(USAGE_HELP, out);
@@ -280,6 +284,8 @@ int main(int argc, char ** argv)
                { "output",     required_argument, NULL, 'o' },
                { "version",    no_argument, NULL, 'V' },
                { "help",       no_argument, NULL, 'h' },
+               { "json",       no_argument, NULL, 'J' },
+               { "raw",        no_argument, NULL, 'r' },
                { NULL, 0, NULL, 0 },
        };
 
@@ -288,7 +294,7 @@ int main(int argc, char ** argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long (argc, argv, "bno:Vh", longopts, NULL)) != -1) {
+       while ((c = getopt_long (argc, argv, "bno:JrVh", longopts, NULL)) != -1) {
                switch (c) {
                case 'b':
                        ctl.bytes = 1;
@@ -299,6 +305,12 @@ int main(int argc, char ** argv)
                case 'o':
                        outarg = optarg;
                        break;
+               case 'J':
+                       ctl.json = 1;
+                       break;
+               case 'r':
+                       ctl.raw = 1;
+                       break;
                case 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
@@ -330,6 +342,10 @@ int main(int argc, char ** argv)
                err(EXIT_FAILURE, _("failed to create output table"));
 
        scols_table_enable_noheadings(ctl.tb, ctl.noheadings);
+       scols_table_enable_raw(ctl.tb, ctl.raw);
+       scols_table_enable_json(ctl.tb, ctl.json);
+       if (ctl.json)
+               scols_table_set_name(ctl.tb, "fincore");
 
        for (i = 0; i < ncolumns; i++) {
                const struct colinfo *col = get_column_info(i);