mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
commands: adjust default help output
Remove the "usage notes" which should just live in the man pages. When there are 3 or more variants of a command, print all the options produces a lot of output, so require --longhelp to print all the options in these cases.
This commit is contained in:
parent
7e411b111f
commit
21fc35dd1b
@ -1229,7 +1229,7 @@ static int is_lvm_all_opt(int opt)
|
|||||||
|
|
||||||
/* Find common options for all variants of each command name. */
|
/* Find common options for all variants of each command name. */
|
||||||
|
|
||||||
static void factor_common_options(void)
|
void factor_common_options(void)
|
||||||
{
|
{
|
||||||
int cn, opt_enum, ci, oo, ro, found;
|
int cn, opt_enum, ci, oo, ro, found;
|
||||||
struct command *cmd;
|
struct command *cmd;
|
||||||
@ -1602,7 +1602,7 @@ static void print_usage_def(struct arg_def *def)
|
|||||||
printf(" ...");
|
printf(" ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_usage(struct command *cmd)
|
void print_usage(struct command *cmd, int longhelp)
|
||||||
{
|
{
|
||||||
struct command_name *cname = find_command_name(cmd->name);
|
struct command_name *cname = find_command_name(cmd->name);
|
||||||
int onereq = (cmd->cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT) ? 1 : 0;
|
int onereq = (cmd->cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT) ? 1 : 0;
|
||||||
@ -1652,6 +1652,9 @@ void print_usage(struct command *cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!longhelp)
|
||||||
|
goto done;
|
||||||
|
|
||||||
if (!cmd->oo_count)
|
if (!cmd->oo_count)
|
||||||
goto op_count;
|
goto op_count;
|
||||||
|
|
||||||
|
@ -213,7 +213,8 @@ struct command {
|
|||||||
|
|
||||||
int define_commands(char *run_name);
|
int define_commands(char *run_name);
|
||||||
int command_id_to_enum(const char *str);
|
int command_id_to_enum(const char *str);
|
||||||
void print_usage(struct command *cmd);
|
void print_usage(struct command *cmd, int longhelp);
|
||||||
void print_usage_common(struct command_name *cname, struct command *cmd);
|
void print_usage_common(struct command_name *cname, struct command *cmd);
|
||||||
|
void factor_common_options(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1564,7 +1564,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
|
|||||||
log_error("Run '%s --help' for more information.", name);
|
log_error("Run '%s --help' for more information.", name);
|
||||||
if (close_ro) {
|
if (close_ro) {
|
||||||
log_warn("Closest command usage is:");
|
log_warn("Closest command usage is:");
|
||||||
print_usage(&_cmdline.commands[close_i]);
|
print_usage(&_cmdline.commands[close_i], 0);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1677,39 +1677,6 @@ 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 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:\n"
|
|
||||||
". Variable parameters are: Number, String, PV, VG, LV, Tag.\n"
|
|
||||||
". Select indicates that a required positional parameter can\n"
|
|
||||||
" be omitted if the --select option is used.\n"
|
|
||||||
". --size Number can be replaced with --extents NumberExtents.\n"
|
|
||||||
". When --name is omitted from lvcreate, a new LV name is\n"
|
|
||||||
" generated with the \"lvol\" prefix and a unique numeric suffix.\n"
|
|
||||||
". The required VG parameter in lvcreate may be omitted when\n"
|
|
||||||
" the VG name is included in another option, e.g. --name VG/LV.\n"
|
|
||||||
". For required options listed in parentheses, e.g. (--A, --B),\n"
|
|
||||||
" any one is required, after which the others are optional.\n"
|
|
||||||
". The _new suffix indicates the VG or LV must not yet exist.\n"
|
|
||||||
". LV followed by _<type> indicates that an LV of the given type\n"
|
|
||||||
" is required. (raid represents any raid<N> type.)\n"
|
|
||||||
". Input units are always treated as base two values, regardless of\n"
|
|
||||||
" unit capitalization, e.g. 'k' and 'K' both refer to 1024.\n"
|
|
||||||
". The default input unit is specified by letter, followed by |unit\n"
|
|
||||||
" which represents other possible input units: bBsSkKmMgGtTpPeE.\n"
|
|
||||||
". Output units can be specified with the --units option, for which\n"
|
|
||||||
" lower/upper case letters refer to base 2/10 values.\n"
|
|
||||||
" formats that are recognized, e.g. for compatibility.\n"
|
|
||||||
". See man pages for short option equivalents of long option names,\n"
|
|
||||||
" and for more detailed descriptions of variable parameters.\n"
|
|
||||||
" \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _usage(const char *name, int longhelp)
|
static int _usage(const char *name, int longhelp)
|
||||||
{
|
{
|
||||||
struct command_name *cname = find_command_name(name);
|
struct command_name *cname = find_command_name(name);
|
||||||
@ -1721,8 +1688,19 @@ static int _usage(const char *name, int longhelp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Looks at all variants of each command name and figures out
|
||||||
|
* which options are common to all variants (for compact output)
|
||||||
|
*/
|
||||||
|
factor_common_options();
|
||||||
|
|
||||||
log_print("%s - %s\n", name, cname->desc);
|
log_print("%s - %s\n", name, cname->desc);
|
||||||
|
|
||||||
|
/* Reduce the default output when there are several variants. */
|
||||||
|
|
||||||
|
if (cname->variants < 3)
|
||||||
|
longhelp = 1;
|
||||||
|
|
||||||
for (i = 0; i < COMMAND_COUNT; i++) {
|
for (i = 0; i < COMMAND_COUNT; i++) {
|
||||||
if (strcmp(_cmdline.commands[i].name, name))
|
if (strcmp(_cmdline.commands[i].name, name))
|
||||||
continue;
|
continue;
|
||||||
@ -1733,15 +1711,15 @@ static int _usage(const char *name, int longhelp)
|
|||||||
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp)
|
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
print_usage(&_cmdline.commands[i]);
|
print_usage(&_cmdline.commands[i], longhelp);
|
||||||
cmd = &_cmdline.commands[i];
|
cmd = &_cmdline.commands[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
if (longhelp)
|
if (longhelp)
|
||||||
_usage_notes();
|
print_usage_common(cname, cmd);
|
||||||
|
else
|
||||||
|
log_print("Use --longhelp to show all options.");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user