summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2017-10-17 19:39:47 +0200
committerDavid Sterba <dsterba@suse.com>2017-11-14 15:59:00 +0100
commitc56d61883c6f093ac905c49f76a99be5e8e09332 (patch)
tree6eb5ba433ee8697aa32a2d7eaab3b101884525c5 /help.c
parenteebdf023215ca0c9268bf7885d10f0d083cf6b70 (diff)
btrfs-progs: help: print multiple syntax schemas on separate lines
The help string for some commands could be split to more lines for clarity, eg. as is now in the receive command. The 'btrfs help' listing should indent all the lines properly, similar the command specific help with "usage:'. The syntax of the first help string line is to separate all command usage schemas by "\n". Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'help.c')
-rw-r--r--help.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/help.c b/help.c
index 99097db..311a432 100644
--- a/help.c
+++ b/help.c
@@ -128,12 +128,32 @@ static int do_usage_one_command(const char * const *usagestr,
unsigned int flags, FILE *outf)
{
int pad = 4;
+ const char *prefix = "usage: ";
+ const char *pad_listing = " ";
if (!usagestr || !*usagestr)
return -1;
- fprintf(outf, "%s%s", (flags & USAGE_LISTING) ? " " : "usage: ",
- *usagestr++);
+ if (flags & USAGE_LISTING)
+ prefix = pad_listing;
+
+ fputs(prefix, outf);
+ if (strchr(*usagestr, '\n') == NULL) {
+ fputs(*usagestr, outf);
+ } else {
+ const char *c = *usagestr;
+ const char *nprefix = " ";
+
+ if (flags & USAGE_LISTING)
+ nprefix = pad_listing;
+
+ for (c = *usagestr; *c; c++) {
+ fputc(*c, outf);
+ if (*c == '\n')
+ fputs(nprefix, outf);
+ }
+ }
+ usagestr++;
/* a short one-line description (mandatory) */
if ((flags & USAGE_SHORT) == 0)