@@ -24,6 +24,15 @@
#include "utils.h"
#include "help.h"
+static const char * const btrfs_short_desc[] = {
+ "For an overview of a given command use 'btrfs command --help'",
+ "or 'btrfs [command...] --help --full' to print all available options.",
+ "Any command name can be shortened as far as it stays unambiguous,",
+ "however it is recommended to use full command names in scripts.",
+ "All command groups have their manual page named 'btrfs-<group>'.",
+ NULL
+};
+
static const char * const btrfs_cmd_group_usage[] = {
"btrfs [--help] [--version] <group> [<group>...] <command> [<args>]",
NULL
@@ -126,7 +135,8 @@ int main(int argc, char **argv)
if (!prefixcmp(argv[0], "--"))
argv[0] += 2;
} else {
- usage_command_group_short(&btrfs_cmd_group);
+ usage_command_group_short(&btrfs_cmd_group,
+ btrfs_short_desc);
exit(1);
}
}
@@ -262,7 +262,8 @@ static void usage_command_group_internal(const struct cmd_group *grp, int full,
}
}
-void usage_command_group_short(const struct cmd_group *grp)
+void usage_command_group_short(const struct cmd_group *grp,
+ const char * const *short_desc)
{
const char * const *usagestr = grp->usagestr;
FILE *outf = stdout;
@@ -298,12 +299,11 @@ void usage_command_group_short(const struct cmd_group *grp)
fprintf(outf, " %-16s %s\n", cmd->token, cmd->usagestr[1]);
}
- fputc('\n', outf);
- fprintf(stderr, "For an overview of a given command use 'btrfs command --help'\n");
- fprintf(stderr, "or 'btrfs [command...] --help --full' to print all available options.\n");
- fprintf(stderr, "Any command name can be shortened as far as it stays unambiguous,\n");
- fprintf(stderr, "however it is recommended to use full command names in scripts.\n");
- fprintf(stderr, "All command groups have their manual page named 'btrfs-<group>'.\n");
+ if (short_desc) {
+ fputc('\n', outf);
+ while (*short_desc && **short_desc)
+ fprintf(outf, "%s\n", *short_desc++);
+ }
}
void usage_command_group(const struct cmd_group *grp, int full, int err)
@@ -58,7 +58,8 @@ struct cmd_group;
void usage(const char * const *usagestr) __attribute__((noreturn));
void usage_command(const struct cmd_struct *cmd, int full, int err);
void usage_command_group(const struct cmd_group *grp, int all, int err);
-void usage_command_group_short(const struct cmd_group *grp);
+void usage_command_group_short(const struct cmd_group *grp,
+ const char * const *short_desc);
void help_unknown_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn));
void help_ambiguous_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn));
usage_command_group_short() always binds its description to 'btrfs', making us unable to this function in other progs. This patch makes the short description independent, so callers need to pass the short description by themselves. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- btrfs.c | 12 +++++++++++- help.c | 14 +++++++------- help.h | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-)