diff --git a/tools/command.c b/tools/command.c index fe8c1f66d..c425fd1a7 100644 --- a/tools/command.c +++ b/tools/command.c @@ -1229,7 +1229,7 @@ static int is_lvm_all_opt(int opt) /* 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; struct command *cmd; @@ -1602,7 +1602,7 @@ static void print_usage_def(struct arg_def *def) printf(" ..."); } -void print_usage(struct command *cmd) +void print_usage(struct command *cmd, int longhelp) { struct command_name *cname = find_command_name(cmd->name); 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) goto op_count; diff --git a/tools/command.h b/tools/command.h index 2d8f628f4..51c455137 100644 --- a/tools/command.h +++ b/tools/command.h @@ -213,7 +213,8 @@ struct command { int define_commands(char *run_name); 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 factor_common_options(void); #endif diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 9fa8d94f5..ecb580207 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -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); if (close_ro) { log_warn("Closest command usage is:"); - print_usage(&_cmdline.commands[close_i]); + print_usage(&_cmdline.commands[close_i], 0); } return NULL; } @@ -1677,39 +1677,6 @@ static void _short_usage(const char *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 _ indicates that an LV of the given type\n" - " is required. (raid represents any raid 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) { struct command_name *cname = find_command_name(name); @@ -1721,8 +1688,19 @@ static int _usage(const char *name, int longhelp) 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); + /* Reduce the default output when there are several variants. */ + + if (cname->variants < 3) + longhelp = 1; + for (i = 0; i < COMMAND_COUNT; i++) { if (strcmp(_cmdline.commands[i].name, name)) continue; @@ -1733,15 +1711,15 @@ static int _usage(const char *name, int longhelp) if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp) continue; - print_usage(&_cmdline.commands[i]); + print_usage(&_cmdline.commands[i], longhelp); 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(); + print_usage_common(cname, cmd); + else + log_print("Use --longhelp to show all options."); return 1; }