1
0
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:
David Teigland 2017-02-14 09:49:26 -06:00
parent c868562a79
commit f46b28bdb6
4 changed files with 64 additions and 45 deletions

View File

@ -244,6 +244,9 @@ arg(locktype_ARG, '\0', "locktype", locktype_VAL, 0, 0,
arg(logonly_ARG, '\0', "logonly", 0, 0, 0, arg(logonly_ARG, '\0', "logonly", 0, 0, 0,
"Suppress command report and display only log report.\n") "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, arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", sizekb_VAL, 0, 0,
"Sets the maximum recovery rate for a RAID LV. The rate value\n" "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" "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. */ /* Not used. */
arg(full_ARG, 'f', "full", 0, 0, 0, NULL) arg(full_ARG, 'f', "full", 0, 0, 0, NULL)
arg(help_ARG, 'h', "help", 0, ARG_COUNTABLE, 0, arg(help_ARG, 'h', "help", 0, 0, 0,
"Display help text. Repeat this option for more information.\n") "Display help text.\n")
arg(cache_ARG, 'H', "cache", 0, 0, 0, arg(cache_ARG, 'H', "cache", 0, 0, 0,
"Specifies the command is handling a cache LV or cache pool.\n" "Specifies the command is handling a cache LV or cache pool.\n"

View File

@ -187,7 +187,7 @@
# OO_ALL is included in every command automatically. # OO_ALL is included in every command automatically.
# #
OO_ALL: --commandprofile String, --config String, --debug, OO_ALL: --commandprofile String, --config String, --debug,
--driverloaded Bool, --help, --profile String, --quiet, --driverloaded Bool, --help, --longhelp, --profile String, --quiet,
--verbose, --version, --yes, --test --verbose, --version, --yes, --test
# #

View File

@ -1640,7 +1640,7 @@ void print_usage(struct command *cmd)
printf(" ]"); printf(" ]");
done: done:
printf("\n"); printf("\n\n");
return; 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 #ifdef MAN_PAGE_GENERATOR

View File

@ -1384,7 +1384,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
continue; continue;
/* For help and version just return the first entry with matching name. */ /* 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]; return &commands[i];
match_required = 0; /* required parameters that match */ match_required = 0; /* required parameters that match */
@ -1661,7 +1661,40 @@ static void _short_usage(const char *name)
log_error("Run `%s --help' for more information.", name); log_error("Run `%s --help' for more information.", name);
} }
static int _usage(const char *name, int help_count) static void _usage_notes(void)
{
/*
* Excluding commonly understood syntax style like the meanings of:
* [ ] for optional, ... for repeatable, | for one of the following,
* -- for an option name, lower case strings and digits for literals.
*/
log_print("Usage notes:");
log_print(". Variable parameters are: Number, String, PV, VG, LV, Tag.");
log_print(". Select indicates that a required positional parameter can");
log_print(" be omitted if the --select option is used.");
log_print(". --size Number can be replaced with --extents NumberExtents.");
log_print(". When --name is omitted from lvcreate, a new LV name is");
log_print(" generated with the \"lvol\" prefix and a unique numeric suffix.");
log_print(". The required VG parameter in lvcreate may be omitted when");
log_print(" the VG name is included in another option, e.g. --name VG/LV.");
log_print(". For required options listed in parentheses, e.g. (--A, --B),");
log_print(" any one is required, after which the others are optional.");
log_print(". The _new suffix indicates the VG or LV must not yet exist.");
log_print(". LV followed by _<type> indicates that an LV of the given type");
log_print(" is required. (raid represents any raid<N> type.)");
log_print(". Input units are always treated as base two values, regardless of");
log_print(" unit capitalization, e.g. 'k' and 'K' both refer to 1024.");
log_print(". The default input unit is specified by letter, followed by |unit");
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(" 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_name *cname = find_command_name(name);
struct command *cmd; struct command *cmd;
@ -1678,52 +1711,33 @@ static int _usage(const char *name, int help_count)
if (strcmp(_cmdline.commands[i].name, name)) if (strcmp(_cmdline.commands[i].name, name))
continue; continue;
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && (help_count < 3)) if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp)
continue; continue;
print_usage(&_cmdline.commands[i]); print_usage(&_cmdline.commands[i]);
cmd = &_cmdline.commands[i]; cmd = &_cmdline.commands[i];
printf("\n");
} }
/* Common options are printed once for all variants of a command name. */ /* Common options are printed once for all variants of a command name. */
print_usage_common(cname, cmd); print_usage_common(cname, cmd);
if (help_count > 1) { if (longhelp)
/* _usage_notes();
* Excluding commonly understood syntax style like the meanings of:
* [ ] for optional, ... for repeatable, | for one of the following,
* -- for an option name, lower case strings and digits for literals.
*/
log_print("Usage notes:");
log_print(". Variable parameters are: Number, String, PV, VG, LV, Tag.");
log_print(". Select indicates that a required positional parameter can");
log_print(" be omitted if the --select option is used.");
log_print(". --size Number can be replaced with --extents NumberExtents.");
log_print(". When --name is omitted from lvcreate, a new LV name is");
log_print(" generated with the \"lvol\" prefix and a unique numeric suffix.");
log_print(". The required VG parameter in lvcreate may be omitted when");
log_print(" the VG name is included in another option, e.g. --name VG/LV.");
log_print(". For required options listed in parentheses, e.g. (--A, --B),");
log_print(" any one is required, after which the others are optional.");
log_print(". The _new suffix indicates the VG or LV must not yet exist.");
log_print(". LV followed by _<type> indicates that an LV of the given type");
log_print(" is required. (raid represents any raid<N> type.)");
log_print(". Input units are always treated as base two values, regardless of");
log_print(" unit capitalization, e.g. 'k' and 'K' both refer to 1024.");
log_print(". The default input unit is specified by letter, followed by |unit");
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.");
}
return 1; 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(). * 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) static int _process_common_commands(struct cmd_context *cmd)
{ {
if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG)) { if (arg_is_set(cmd, help_ARG) ||
_usage(cmd->name, arg_count(cmd, help_ARG)); arg_is_set(cmd, longhelp_ARG) ||
arg_is_set(cmd, help2_ARG)) {
if (arg_count(cmd, help_ARG) < 2) _usage(cmd->name, arg_is_set(cmd, longhelp_ARG));
log_print("(Use --help --help for usage notes.)");
return ECMD_PROCESSED; return ECMD_PROCESSED;
} }
@ -2195,6 +2208,8 @@ int help(struct cmd_context *cmd __attribute__((unused)), int argc, char **argv)
if (!argc) if (!argc)
_display_help(); _display_help();
else if (argc == 1 && !strcmp(argv[0], "all"))
_usage_all();
else { else {
int i; int i;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)