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 <dsterba@suse.com>
This commit is contained in:
David Sterba 2019-06-21 16:11:07 +02:00
parent a1a5000984
commit eb6a09050f
2 changed files with 31 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;