From eb6a09050f1350e66016975a48dd00b7fb60093c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 21 Jun 2019 16:11:07 +0200 Subject: [PATCH] btrfs-progs: help: add helpinfo marker for global options Global options should be printed right after the command options, but there could be text following the options. Add a marker that will allow to order the options before that text. Signed-off-by: David Sterba --- common/help.c | 27 ++++++++++++++++++++++++--- common/help.h | 7 +++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/common/help.c b/common/help.c index b6763b32..0b4ab71a 100644 --- a/common/help.c +++ b/common/help.c @@ -205,10 +205,31 @@ static int do_usage_one_command(const char * const *usagestr, * description) be prepended with an empty line, skip it */ usagestr++; - fputc('\n', outf); - while (*usagestr) - fprintf(outf, "%*s%s\n", pad, "", *usagestr++); + + while (*usagestr) { + if (strcmp(*usagestr, HELPINFO_INSERT_GLOBALS) == 0) { + int i; + + fputc('\n', outf); + /* + * We always support text, that's on by default for all + * commands + */ + fprintf(outf, "%*sGlobal options:\n", pad, ""); + fprintf(outf, "%*s--format TYPE where TYPE is: %s", + pad, "", output_formats[0].name); + for (i = 1; i < ARRAY_SIZE(output_formats); i++) { + if (cmd_flags & output_formats[i].value) + fprintf(outf, ", %s", + output_formats[i].name); + } + fputc('\n', outf); + } else { + fprintf(outf, "%*s%s\n", pad, "", *usagestr); + } + usagestr++; + } return 0; } diff --git a/common/help.h b/common/help.h index 47eabcc2..ac3816a4 100644 --- a/common/help.h +++ b/common/help.h @@ -52,6 +52,13 @@ "-g|--gbytes show sizes in GiB, or GB with --si", \ "-t|--tbytes show sizes in TiB, or TB with --si" +/* + * Special marker in the help strings that will preemptively insert the global + * options and then continue with the following text that possibly follows + * after the regular options + */ +#define HELPINFO_INSERT_GLOBALS "INSERT_GLOBALS" + struct cmd_struct; struct cmd_group;