mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
commands: improve help/usage output
Replace --help --help with --long-help. Some blank lines were needed. Add 'lvm help all' to print help for all commands.
This commit is contained in:
parent
c868562a79
commit
f46b28bdb6
@ -244,6 +244,9 @@ arg(locktype_ARG, '\0', "locktype", locktype_VAL, 0, 0,
|
||||
arg(logonly_ARG, '\0', "logonly", 0, 0, 0,
|
||||
"Suppress command report and display only log report.\n")
|
||||
|
||||
arg(longhelp_ARG, '\0', "longhelp", 0, 0, 0,
|
||||
"Display long help text.\n")
|
||||
|
||||
arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", sizekb_VAL, 0, 0,
|
||||
"Sets the maximum recovery rate for a RAID LV. The rate value\n"
|
||||
"is an amount of data per second for each device in the array.\n"
|
||||
@ -920,8 +923,8 @@ arg(force_ARG, 'f', "force", 0, ARG_COUNTABLE, 0,
|
||||
/* Not used. */
|
||||
arg(full_ARG, 'f', "full", 0, 0, 0, NULL)
|
||||
|
||||
arg(help_ARG, 'h', "help", 0, ARG_COUNTABLE, 0,
|
||||
"Display help text. Repeat this option for more information.\n")
|
||||
arg(help_ARG, 'h', "help", 0, 0, 0,
|
||||
"Display help text.\n")
|
||||
|
||||
arg(cache_ARG, 'H', "cache", 0, 0, 0,
|
||||
"Specifies the command is handling a cache LV or cache pool.\n"
|
||||
|
@ -187,7 +187,7 @@
|
||||
# OO_ALL is included in every command automatically.
|
||||
#
|
||||
OO_ALL: --commandprofile String, --config String, --debug,
|
||||
--driverloaded Bool, --help, --profile String, --quiet,
|
||||
--driverloaded Bool, --help, --longhelp, --profile String, --quiet,
|
||||
--verbose, --version, --yes, --test
|
||||
|
||||
#
|
||||
|
@ -1640,7 +1640,7 @@ void print_usage(struct command *cmd)
|
||||
|
||||
printf(" ]");
|
||||
done:
|
||||
printf("\n");
|
||||
printf("\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1704,7 +1704,8 @@ void print_usage_common(struct command_name *cname, struct command *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
printf(" ]\n");
|
||||
printf(" ]");
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
#ifdef MAN_PAGE_GENERATOR
|
||||
|
@ -1384,7 +1384,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
|
||||
continue;
|
||||
|
||||
/* For help and version just return the first entry with matching name. */
|
||||
if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG) || arg_is_set(cmd, version_ARG))
|
||||
if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG) || arg_is_set(cmd, longhelp_ARG) || arg_is_set(cmd, version_ARG))
|
||||
return &commands[i];
|
||||
|
||||
match_required = 0; /* required parameters that match */
|
||||
@ -1661,35 +1661,8 @@ static void _short_usage(const char *name)
|
||||
log_error("Run `%s --help' for more information.", name);
|
||||
}
|
||||
|
||||
static int _usage(const char *name, int help_count)
|
||||
static void _usage_notes(void)
|
||||
{
|
||||
struct command_name *cname = find_command_name(name);
|
||||
struct command *cmd;
|
||||
int i;
|
||||
|
||||
if (!cname) {
|
||||
log_print("%s: no such command.", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("%s - %s\n", name, cname->desc);
|
||||
|
||||
for (i = 0; i < COMMAND_COUNT; i++) {
|
||||
if (strcmp(_cmdline.commands[i].name, name))
|
||||
continue;
|
||||
|
||||
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && (help_count < 3))
|
||||
continue;
|
||||
|
||||
print_usage(&_cmdline.commands[i]);
|
||||
cmd = &_cmdline.commands[i];
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Common options are printed once for all variants of a command name. */
|
||||
print_usage_common(cname, cmd);
|
||||
|
||||
if (help_count > 1) {
|
||||
/*
|
||||
* Excluding commonly understood syntax style like the meanings of:
|
||||
* [ ] for optional, ... for repeatable, | for one of the following,
|
||||
@ -1715,15 +1688,56 @@ static int _usage(const char *name, int help_count)
|
||||
log_print(" which represents other possible input units: bBsSkKmMgGtTpPeE.");
|
||||
log_print(". Output units can be specified with the --units option, for which");
|
||||
log_print(" lower/upper case letters refer to base 2/10 values.");
|
||||
log_print(". Use --help --help --help to print secondary command syntax");
|
||||
log_print(" formats that are recognized, e.g. for compatibility.");
|
||||
log_print(". See man pages for short option equivalents of long option names,");
|
||||
log_print(" and for more detailed descriptions of variable parameters.");
|
||||
log_print(" ");
|
||||
}
|
||||
|
||||
static int _usage(const char *name, int longhelp)
|
||||
{
|
||||
struct command_name *cname = find_command_name(name);
|
||||
struct command *cmd;
|
||||
int i;
|
||||
|
||||
if (!cname) {
|
||||
log_print("%s: no such command.", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_print("%s - %s\n", name, cname->desc);
|
||||
|
||||
for (i = 0; i < COMMAND_COUNT; i++) {
|
||||
if (strcmp(_cmdline.commands[i].name, name))
|
||||
continue;
|
||||
|
||||
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp)
|
||||
continue;
|
||||
|
||||
print_usage(&_cmdline.commands[i]);
|
||||
cmd = &_cmdline.commands[i];
|
||||
}
|
||||
|
||||
/* Common options are printed once for all variants of a command name. */
|
||||
print_usage_common(cname, cmd);
|
||||
|
||||
if (longhelp)
|
||||
_usage_notes();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _usage_all(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_COMMAND_NAMES; i++) {
|
||||
if (!command_names[i].name)
|
||||
break;
|
||||
_usage(command_names[i].name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets up the arguments to pass to getopt_long().
|
||||
*
|
||||
@ -2158,11 +2172,10 @@ static int _get_settings(struct cmd_context *cmd)
|
||||
|
||||
static int _process_common_commands(struct cmd_context *cmd)
|
||||
{
|
||||
if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG)) {
|
||||
_usage(cmd->name, arg_count(cmd, help_ARG));
|
||||
|
||||
if (arg_count(cmd, help_ARG) < 2)
|
||||
log_print("(Use --help --help for usage notes.)");
|
||||
if (arg_is_set(cmd, help_ARG) ||
|
||||
arg_is_set(cmd, longhelp_ARG) ||
|
||||
arg_is_set(cmd, help2_ARG)) {
|
||||
_usage(cmd->name, arg_is_set(cmd, longhelp_ARG));
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
@ -2195,6 +2208,8 @@ int help(struct cmd_context *cmd __attribute__((unused)), int argc, char **argv)
|
||||
|
||||
if (!argc)
|
||||
_display_help();
|
||||
else if (argc == 1 && !strcmp(argv[0], "all"))
|
||||
_usage_all();
|
||||
else {
|
||||
int i;
|
||||
for (i = 0; i < argc; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user