From 8ed48785e1d5266211884540350afa22cd1513a3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 10 May 2011 11:39:51 +0200 Subject: partx: add --pairs to output in key="value" format Signed-off-by: Karel Zak --- partx/partx.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'partx/partx.c') diff --git a/partx/partx.c b/partx/partx.c index 7c89cf57b..5979701c5 100644 --- a/partx/partx.c +++ b/partx/partx.c @@ -608,13 +608,14 @@ static void __attribute__((__noreturn__)) usage(FILE *out) " -b, --bytes print SIZE in bytes rather than in human readable format\n" " -g, --noheadings don't print headings for --show\n" - " -r, --raw use raw format output\n" + " -P, --pairs use key=\"value\" output format\n" + " -r, --raw use raw output format\n" " -t, --type specify the partition type (dos, bsd, solaris, etc.)\n" " -n, --nr specify the range of partitions (e.g. --nr 2:4)\n" " -o, --output define which output columns to use\n" " -h, --help print this help\n\n")); - fprintf(out, _("\nAvailable columns (for --show):\n")); + fprintf(out, _("\nAvailable columns (for --show, --raw or --pairs):\n")); for (i = 0; i < __NCOLUMNS; i++) fprintf(out, " %10s %s\n", infos[i].name, _(infos[i].help)); @@ -650,53 +651,60 @@ int main(int argc, char **argv) { "type", required_argument, NULL, 't' }, { "nr", required_argument, NULL, 'n' }, { "output", required_argument, NULL, 'o' }, + { "pairs", no_argument, NULL, 'P' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "abdglrsvn:t:o:h", long_opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, + "abdglrsvn:t:o:Ph", long_opts, NULL)) != -1) { + switch(c) { case 'a': + case 'd': + case 'l': + case 'r': + case 'P': + case 's': if (what) - errx_mutually_exclusive("--{add,delete,show,list,raw}"); + errx_mutually_exclusive("--{add,delete,show,list,raw,pairs}"); + break; + } + + switch(c) { + case 'a': what = ACT_ADD; break; case 'b': partx_flags |= FL_BYTES; break; case 'd': - if (what) - errx_mutually_exclusive("--{add,delete,show,list,raw}"); what = ACT_DELETE; break; case 'g': tt_flags |= TT_FL_NOHEADINGS; break; case 'l': - if (what) - errx_mutually_exclusive("--{add,delete,show,list,raw}"); what = ACT_LIST; break; case 'n': if (parse_range(optarg, &lower, &upper)) errx(EXIT_FAILURE, _("failed to parse --nr range")); break; - case 'o': if (tt_parse_columns_list(optarg, columns, &ncolumns, column_name_to_id)) return EXIT_FAILURE; break; + case 'P': + tt_flags |= TT_FL_EXPORT; + what = ACT_SHOW; + break; case 'r': tt_flags |= TT_FL_RAW; - if (what) - errx_mutually_exclusive("--{add,delete,show,list,raw}"); what = ACT_SHOW; break; - case 's': - if (what) - errx_mutually_exclusive("--{add,delete,show,list,raw}"); what = ACT_SHOW; break; case 't': -- cgit v1.2.3-55-g7522