diff --git a/tools/command.c b/tools/command.c index 7c5bf7ce8..e0db50383 100644 --- a/tools/command.c +++ b/tools/command.c @@ -1597,7 +1597,7 @@ static void print_usage_def(struct arg_def *def) printf(" ..."); } -void print_usage(struct command *cmd, int longhelp) +void print_usage(struct command *cmd, int longhelp, int desc_first) { struct command_name *cname = find_command_name(cmd->name); int onereq = (cmd->cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT) ? 1 : 0; @@ -1609,7 +1609,7 @@ void print_usage(struct command *cmd, int longhelp) */ factor_common_options(); - if (cmd->desc) + if (desc_first && cmd->desc) _print_usage_description(cmd); printf(" %s", cmd->name); @@ -1709,7 +1709,12 @@ void print_usage(struct command *cmd, int longhelp) printf(" ]"); done: - printf("\n\n"); + printf("\n"); + + if (!desc_first && cmd->desc) + _print_usage_description(cmd); + + printf("\n"); return; } diff --git a/tools/command.h b/tools/command.h index c5c801a05..36554a369 100644 --- a/tools/command.h +++ b/tools/command.h @@ -213,7 +213,7 @@ struct command { int define_commands(char *run_name); int command_id_to_enum(const char *str); -void print_usage(struct command *cmd, int longhelp); +void print_usage(struct command *cmd, int longhelp, int desc_first); void print_usage_common_cmd(struct command_name *cname, struct command *cmd); void print_usage_common_lvm(struct command_name *cname, struct command *cmd); void factor_common_options(void); diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index e2be7c70d..f5b095c90 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1560,11 +1560,10 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path, if (!best_required) { /* cmd did not have all the required opt/pos args of any command */ - log_error("Failed to find a matching command definition."); - log_error("Run '%s --help' for more information.", name); + log_error("Incorrect syntax. Run '%s --help' for more information.", name); if (close_ro) { - log_warn("Closest command usage is:"); - print_usage(&_cmdline.commands[close_i], 0); + log_warn("Nearest similar command has syntax:"); + print_usage(&_cmdline.commands[close_i], 0, 0); } return NULL; } @@ -1711,7 +1710,7 @@ 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], longhelp); + print_usage(&_cmdline.commands[i], longhelp, 1); cmd = &_cmdline.commands[i]; }