From: Karel Zak Date: Tue, 10 May 2011 08:38:29 +0000 (+0200) Subject: lsblk: add --pairs to output in key="value" format X-Git-Tag: v2.20-rc1~291 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ea1bdd32c62622d12517f86d471aec2aa79e4bb;p=thirdparty%2Futil-linux.git lsblk: add --pairs to output in key="value" format Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8 index d7d7aa8b4d..2fcc7e5221 100644 --- a/misc-utils/lsblk.8 +++ b/misc-utils/lsblk.8 @@ -42,7 +42,7 @@ command. .IP "\fB\-h, \-\-help\fP" Print a help text and exit. .IP "\fB\-i, \-\-ascii\fP" -Use ascii characters for tree formatting. +Use ASCII characters for tree formatting. .IP "\fB\-m, \-\-perms\fP Output info about device owner, group and mode. This option is equivalent to "-o NAME,SIZE,OWNER,GROUP,MODE". .IP "\fB\-l, \-\-list\fP" @@ -53,6 +53,8 @@ Do not print a header line. Specify which output columns to print. Use .B "--help" to get a list of all supported columns. +.IP "\fB\-P, \-\-pairs\fP" +Use key="value" output format. .IP "\fB\-r, \-\-raw\fP" Use the raw output format. .IP "\fB\-t, \-\-topology\fP" diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index dc4e15aafd..2110113dd6 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -612,7 +612,8 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line break; } case COL_MAJMIN: - if (lsblk->tt->flags & TT_FL_RAW) + if ((lsblk->tt->flags & TT_FL_RAW) || + (lsblk->tt->flags & TT_FL_EXPORT)) snprintf(buf, sizeof(buf), "%u:%u", cxt->maj, cxt->min); else snprintf(buf, sizeof(buf), "%3u:%-3u", cxt->maj, cxt->min); @@ -971,7 +972,8 @@ static void __attribute__((__noreturn__)) help(FILE *out) " -l, --list use list format ouput\n" " -n, --noheadings don't print headings\n" " -o, --output output columns\n" - " -r, --raw use raw format output\n" + " -P, --pairs use key=\"value\" output format\n" + " -r, --raw use raw output format\n" " -t, --topology output info about topology\n")); fprintf(out, _("\nAvailable columns:\n")); @@ -1011,6 +1013,7 @@ int main(int argc, char *argv[]) { "fs", 0, 0, 'f' }, { "exclude", 1, 0, 'e' }, { "topology", 0, 0, 't' }, + { "pairs", 0, 0, 'P' }, { NULL, 0, 0, 0 }, }; @@ -1021,7 +1024,7 @@ int main(int argc, char *argv[]) lsblk = &_ls; memset(lsblk, 0, sizeof(*lsblk)); - while((c = getopt_long(argc, argv, "abdDe:fhlnmo:irt", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "abdDe:fhlnmo:Pirt", longopts, NULL)) != -1) { switch(c) { case 'a': lsblk->all_devices = 1; @@ -1046,8 +1049,8 @@ int main(int argc, char *argv[]) help(stdout); break; case 'l': - if (tt_flags & TT_FL_RAW) - errx_mutually_exclusive("--{raw,list}"); + if ((tt_flags & TT_FL_RAW)|| (tt_flags & TT_FL_EXPORT)) + errx_mutually_exclusive("--{raw,list,export}"); tt_flags &= ~TT_FL_TREE; /* disable the default */ break; @@ -1059,6 +1062,10 @@ int main(int argc, char *argv[]) column_name_to_id)) return EXIT_FAILURE; break; + case 'P': + tt_flags |= TT_FL_EXPORT; + tt_flags &= ~TT_FL_TREE; /* disable the default */ + break; case 'i': tt_flags |= TT_FL_ASCII; break;