if (scols_table_is_noheadings(tb) ||
scols_table_is_export(tb) ||
+ scols_table_is_json(tb) ||
list_empty(&tb->tb_lines))
return 0;
return -EINVAL;
DBG(TAB, ul_debugobj(tb, "printing"));
+
+ if (list_empty(&tb->tb_lines)) {
+ DBG(TAB, ul_debugobj(tb, "ignore -- epmty table"));
+ return 0;
+ }
+
if (!tb->symbols)
scols_table_set_symbols(tb, NULL); /* use default */
if (!buf)
return -ENOMEM;
- if (!(scols_table_is_raw(tb) || scols_table_is_export(tb))) {
+ if (tb->format == SCOLS_FMT_HUMAN) {
rc = recount_widths(tb, buf);
if (rc != 0)
goto done;
fput_table_open(tb);
- if (!scols_table_is_json(tb)) {
- rc = print_header(tb, buf);
- if (rc)
- goto done;
- }
+ rc = print_header(tb, buf);
+ if (rc)
+ goto done;
if (scols_table_is_tree(tb))
rc = print_tree(tb, buf);
Show the status of all loop devices associated with the given
.IR file .
.TP
+.IP "\fB\-J, \fB\-\-json\fP"
+Use JSON format for \fB\-\-list\fP output.
+.TP
.BR \-l , " \-\-list"
If a loop device or the \fB-a\fR option is specified, print the default columns
for either the specified loop device or all loop devices; the default is to
print info about all devices. See also \fB\-\-output\fP, \fB\-\-noheadings\fP
-and \fB\-\-raw\fP.
+\fB\-\-json\fP and \fB\-\-raw\fP.
.TP
.BR \-n , " \-\-noheadings"
Don't print headings for \fB\-\-list\fP output format.
/* basic output flags */
static int no_headings;
static int raw;
+static int json;
struct colinfo {
const char *name;
if (!(tb = scols_new_table()))
err(EXIT_FAILURE, _("failed to initialize output table"));
scols_table_enable_raw(tb, raw);
+ scols_table_enable_json(tb, json);
scols_table_enable_noheadings(tb, no_headings);
+ if (json)
+ scols_table_set_name(tb, "loopdevices");
+
for (i = 0; i < ncolumns; i++) {
struct colinfo *ci = get_column_info(i);
fputs(_(" -O, --output <cols> specify columns to output for --list\n"), out);
fputs(_(" -n, --noheadings don't print headings for --list output\n"), out);
fputs(_(" --raw use raw --list output format\n"), out);
+ fputs(_(" -J, --json use JSON --list output format\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
{ "find", 0, 0, 'f' },
{ "help", 0, 0, 'h' },
{ "associated", 1, 0, 'j' },
+ { "json", 0, 0, 'J' },
{ "list", 0, 0, 'l' },
{ "noheadings", 0, 0, 'n' },
{ "offset", 1, 0, 'o' },
{ 'D','a','c','d','f','j' },
{ 'D','c','d','f','l' },
{ 'D','c','d','f','O' },
+ { 'J',OPT_RAW },
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
if (loopcxt_init(&lc, 0))
err(EXIT_FAILURE, _("failed to initialize loopcxt"));
- while ((c = getopt_long(argc, argv, "ac:d:Dfhj:lno:O:PrvV",
+ while ((c = getopt_long(argc, argv, "ac:d:Dfhj:Jlno:O:PrvV",
longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
case 'h':
usage(stdout);
break;
+ case 'J':
+ json = 1;
+ break;
case 'j':
act = A_SHOW;
file = optarg;
list = 1;
}
+ if (!act && argc == 2 && (raw || json)) {
+ act = A_SHOW;
+ list = 1;
+ }
+
/* default --list output columns */
if (list && !ncolumns) {
columns[ncolumns++] = COL_NAME;