X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=help.c;h=e57d9f280b151df7e88f1f75e4961e36670bef4d;hb=12aba72aed310d6d3215684c44849233df7d79d2;hp=d429a6b0026baec9cac2a18858e9c804bf096b95;hpb=d1dc0919808b4a80c47ca720e5ff610ed6f4a1b5;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/help.c b/help.c index d429a6b..e57d9f2 100644 --- a/help.c +++ b/help.c @@ -17,10 +17,10 @@ #include #include #include +#include #include "commands.h" - -static char argv0_buf[ARGV0_BUF_SIZE]; +#include "utils.h" #define USAGE_SHORT 1U #define USAGE_LONG 2U @@ -121,7 +121,7 @@ void usage_command(const struct cmd_struct *cmd, int full, int err) void usage(const char * const *usagestr) { usage_command_usagestr(usagestr, NULL, 1, 1); - exit(129); + exit(1); } static void usage_command_group_internal(const struct cmd_group *grp, int full, @@ -131,7 +131,7 @@ static void usage_command_group_internal(const struct cmd_group *grp, int full, int do_sep = 0; for (; cmd->token; cmd++) { - if (cmd->hidden) + if (cmd->flags & CMD_HIDDEN) continue; if (full && cmd != grp->commands) @@ -160,6 +160,50 @@ static void usage_command_group_internal(const struct cmd_group *grp, int full, } } +void usage_command_group_short(const struct cmd_group *grp) +{ + const char * const *usagestr = grp->usagestr; + FILE *outf = stdout; + const struct cmd_struct *cmd; + + if (usagestr && *usagestr) { + fprintf(outf, "usage: %s\n", *usagestr++); + while (*usagestr) + fprintf(outf, " or: %s\n", *usagestr++); + } + + fputc('\n', outf); + + fprintf(outf, "Command groups:\n"); + for (cmd = grp->commands; cmd->token; cmd++) { + if (cmd->flags & CMD_HIDDEN) + continue; + + if (!cmd->next) + continue; + + fprintf(outf, " %-16s %s\n", cmd->token, cmd->next->infostr); + } + + fprintf(outf, "\nCommands:\n"); + for (cmd = grp->commands; cmd->token; cmd++) { + if (cmd->flags & CMD_HIDDEN) + continue; + + if (cmd->next) + continue; + + 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-'.\n"); +} + void usage_command_group(const struct cmd_group *grp, int full, int err) { const char * const *usagestr = grp->usagestr; @@ -181,7 +225,7 @@ void usage_command_group(const struct cmd_group *grp, int full, int err) void help_unknown_token(const char *arg, const struct cmd_group *grp) { - fprintf(stderr, "%s: unknown token '%s'\n", argv0_buf, arg); + fprintf(stderr, "%s: unknown token '%s'\n", get_argv0_buf(), arg); usage_command_group(grp, 0, 1); exit(1); } @@ -190,7 +234,7 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp) { const struct cmd_struct *cmd = grp->commands; - fprintf(stderr, "%s: ambiguous token '%s'\n", argv0_buf, arg); + fprintf(stderr, "%s: ambiguous token '%s'\n", get_argv0_buf(), arg); fprintf(stderr, "\nDid you mean one of these ?\n"); for (; cmd->token; cmd++) {