if (!usagestr || !*usagestr)
return -1;
- fprintf(outf, "%s%s\n", (flags & USAGE_LISTING) ? " " : "usage: ",
+ fprintf(outf, "%s%s", (flags & USAGE_LISTING) ? " " : "usage: ",
*usagestr++);
/* a short one-line description (mandatory) */
return 0;
else if (!*usagestr)
return -2;
+ fputc('\n', outf);
if (flags & USAGE_LISTING)
pad = 8;
static int usage_command_internal(const char * const *usagestr,
const char *token, int full, int lst,
- FILE *outf)
+ int alias, FILE *outf)
{
- unsigned int flags = USAGE_SHORT;
+ unsigned int flags = 0;
int ret;
+ if (!alias)
+ flags |= USAGE_SHORT;
if (full)
flags |= USAGE_LONG | USAGE_OPTIONS;
if (lst)
FILE *outf = err ? stderr : stdout;
int ret;
- ret = usage_command_internal(usagestr, token, full, 0, outf);
+ ret = usage_command_internal(usagestr, token, full, 0, 0, outf);
if (!ret)
fputc('\n', outf);
}
int do_sep = 0;
for (; cmd->token; cmd++) {
- if (cmd->hidden)
+ if (cmd->flags & CMD_HIDDEN)
continue;
if (full && cmd != grp->commands)
}
usage_command_internal(cmd->usagestr, cmd->token, full,
- 1, outf);
+ 1, cmd->flags & CMD_ALIAS, outf);
continue;
}
}
}
+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-<group>'.\n");
+}
+
void usage_command_group(const struct cmd_group *grp, int full, int err)
{
const char * const *usagestr = grp->usagestr;
usage_command_group(grp, full, 0);
}
+
+int prefixcmp(const char *str, const char *prefix)
+{
+ for (; ; str++, prefix++)
+ if (!*prefix)
+ return 0;
+ else if (*str != *prefix)
+ return (unsigned char)*prefix - (unsigned char)*str;
+}
+