diff options
author | Karel Zak | 2015-06-04 15:49:52 +0200 |
---|---|---|
committer | Karel Zak | 2015-06-04 15:49:52 +0200 |
commit | 4a102a4871fdb415f4de5af9ffb7a2fb8926b5d1 (patch) | |
tree | 3840a0c663a0521950f91b3c3e5a7a6d3bcfa61f /misc-utils/lsblk.c | |
parent | libsmartcols: add JSON output format (diff) | |
download | kernel-qcow2-util-linux-4a102a4871fdb415f4de5af9ffb7a2fb8926b5d1.tar.gz kernel-qcow2-util-linux-4a102a4871fdb415f4de5af9ffb7a2fb8926b5d1.tar.xz kernel-qcow2-util-linux-4a102a4871fdb415f4de5af9ffb7a2fb8926b5d1.zip |
lsblk: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r-- | misc-utils/lsblk.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 37fbb9af2..cfd304a7e 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -135,6 +135,7 @@ enum { LSBLK_NOHEADINGS = (1 << 2), LSBLK_EXPORT = (1 << 3), LSBLK_TREE = (1 << 4), + LSBLK_JSON = (1 << 5), }; enum { @@ -780,7 +781,8 @@ static char *get_subsystems(struct blkdev_cxt *cxt) #define is_parsable(_l) (scols_table_is_raw((_l)->table) || \ - scols_table_is_export((_l)->table)) + scols_table_is_export((_l)->table) || \ + scols_table_is_json((_l)->table)) static char *mk_name(const char *name) { @@ -1609,6 +1611,7 @@ static void __attribute__((__noreturn__)) help(FILE *out) fputs(_(" -f, --fs output info about filesystems\n"), out); fputs(_(" -i, --ascii use ascii characters only\n"), out); fputs(_(" -I, --include <list> show only devices with specified major numbers\n"), out); + fputs(_(" -J, --json use JSON output format\n"), out); fputs(_(" -l, --list use list format output\n"), out); fputs(_(" -m, --perms output info about permissions\n"), out); fputs(_(" -n, --noheadings don't print headings\n"), out); @@ -1656,6 +1659,7 @@ int main(int argc, char *argv[]) { "nodeps", 0, 0, 'd' }, { "discard", 0, 0, 'D' }, { "help", 0, 0, 'h' }, + { "json", 0, 0, 'J' }, { "output", 1, 0, 'o' }, { "output-all", 0, 0, 'O' }, { "perms", 0, 0, 'm' }, @@ -1679,6 +1683,7 @@ int main(int argc, char *argv[]) static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */ { 'D','O' }, { 'I','e' }, + { 'J', 'P', 'r' }, { 'O','S' }, { 'O','f' }, { 'O','m' }, @@ -1698,7 +1703,7 @@ int main(int argc, char *argv[]) lsblk_init_debug(); while((c = getopt_long(argc, argv, - "abdDe:fhlnmo:OpPiI:rstVSx:", longopts, NULL)) != -1) { + "abdDe:fhJlnmo:OpPiI:rstVSx:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -1725,6 +1730,9 @@ int main(int argc, char *argv[]) case 'h': help(stdout); break; + case 'J': + scols_flags |= LSBLK_JSON; + break; case 'l': scols_flags &= ~LSBLK_TREE; /* disable the default */ break; @@ -1843,8 +1851,12 @@ int main(int argc, char *argv[]) scols_table_enable_raw(lsblk->table, !!(scols_flags & LSBLK_RAW)); scols_table_enable_export(lsblk->table, !!(scols_flags & LSBLK_EXPORT)); scols_table_enable_ascii(lsblk->table, !!(scols_flags & LSBLK_ASCII)); + scols_table_enable_json(lsblk->table, !!(scols_flags & LSBLK_JSON)); scols_table_enable_noheadings(lsblk->table, !!(scols_flags & LSBLK_NOHEADINGS)); + if (scols_flags & LSBLK_JSON) + scols_table_set_name(lsblk->table, "blockdevices"); + for (i = 0; i < ncolumns; i++) { struct colinfo *ci = get_column_info(i); struct libscols_column *cl; |