diff options
author | David Teigland <teigland@redhat.com> | 2021-04-20 17:03:09 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2021-04-21 08:41:37 -0500 |
commit | d651b340e68d97ada25e558eb50aa40062bba936 (patch) | |
tree | d0cfd6fee3bf89c2a2c7a1b60c9bf171678d19e5 /tools/command.c | |
parent | 7b77226df2ee7f4d1baa11d42752f600e408bf65 (diff) | |
download | lvm2-d651b340e68d97ada25e558eb50aa40062bba936.tar.gz |
commands: use AUTOTYPE in definitions
If a cmd def implies an LV type without --type
in the required options, then include the implied
type in the cmd def as AUTOTYPE: <type>
instead of including the redundant --type foo
in the OO list of options.
Including an implied --type in the OO list would
often cause multiple cmd defs to potentially be
identical when options were used, and a user
command could match more than one cmd def.
The AUTOTYPE values are listed in man page and
help output as
[ --type foo (implied) ]
If a user command includes --type, it will usually
match a cmd def with --type in the required options.
But, if the user command matches a cmd def with
AUTOTYPE, then the specifed --type and AUTOTYPE must
match.
The man-generator program has a new --check
option that compares cmd defs to find any cmd defs
that are equivalent with the use of options,
and should have their options adjusted.
Diffstat (limited to 'tools/command.c')
-rw-r--r-- | tools/command.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/command.c b/tools/command.c index d6e0fec57..99661a517 100644 --- a/tools/command.c +++ b/tools/command.c @@ -645,6 +645,13 @@ static int _is_desc_line(char *str) return 0; } +static int _is_autotype_line(char *str) +{ + if (!strncmp(str, "AUTOTYPE:", 6)) + return 1; + return 0; +} + static int _is_flags_line(char *str) { if (!strncmp(str, "FLAGS:", 6)) @@ -1209,6 +1216,19 @@ static void _add_flags(struct command *cmd, char *line) cmd->cmd_flags |= CMD_FLAG_PREVIOUS_SYNTAX; } +static void _add_autotype(struct cmd_context *cmdtool, struct command *cmd, char *line) +{ + int line_argc; + char *line_argv[MAX_LINE_ARGC]; + + _split_line(line, &line_argc, line_argv, ' '); + + if (cmd->autotype) + cmd->autotype2 = dm_pool_strdup(cmdtool->libmem, line_argv[1]); + else + cmd->autotype = dm_pool_strdup(cmdtool->libmem, line_argv[1]); +} + #define MAX_RULE_OPTS 64 static void _add_rule(struct cmd_context *cmdtool, struct command *cmd, char *line) @@ -1535,6 +1555,11 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name) continue; } + if (_is_autotype_line(line_argv[0]) && !skip && cmd) { + _add_autotype(cmdtool, cmd, line_orig); + continue; + } + if (_is_flags_line(line_argv[0]) && !skip && cmd) { _add_flags(cmd, line_orig); continue; @@ -1951,6 +1976,14 @@ void print_usage(struct command *cmd, int longhelp, int desc_first) goto op_count; if (cmd->oo_count) { + if (cmd->autotype) { + printf("\n\t"); + if (!cmd->autotype2) + printf("[ --type %s (implied) ]", cmd->autotype); + else + printf("[ --type %s|%s (implied) ]", cmd->autotype, cmd->autotype2); + } + if (include_extents) { printf("\n\t[ -l|--extents "); _print_val_usage(cmd, extents_ARG, opt_names[extents_ARG].val_enum); @@ -2727,6 +2760,15 @@ static void _print_man_usage(char *lvmname, struct command *cmd) printf(".RS 4\n"); printf(".ad l\n"); + if (cmd->autotype) { + if (!cmd->autotype2) + printf("[ \\fB--type %s\\fP (implied) ]\n", cmd->autotype); + else + printf("[ \\fB--type %s\\fP|\\fB%s\\fP (implied) ]\n", cmd->autotype, cmd->autotype2); + printf(".br\n"); + sep = 1; + } + if (include_extents) { /* * NB we don't just pass extents_VAL here because the |