1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

man: add ARG_MAN_ALIAS_OPT alias support

For some options we need specific specialization for certain commands.
To make the solution 'generic' let's introduce ARG_MAN_ALIAS_OPT flag.
Such an option then can be used  in command-lines.in file
to reference the specific instance of a common option.

Original option is stored as _ARG within short_opt field
(so we do not add new field to every arg for this)
Then command is supposed to accepted only original option.
However with the man page creation we can have individual
versions of such an option.
This commit is contained in:
Zdenek Kabelac 2024-11-20 13:09:54 +01:00
parent bee8c1b921
commit 8d2cb42166
4 changed files with 18 additions and 3 deletions

View File

@ -256,6 +256,10 @@ static int _opt_str_to_num(struct command *cmd, const char *str)
* check left & right side for possible match
*/
for (i = middle;;) {
#ifndef MAN_PAGE_GENERATOR
if (!p && (opt_names_alpha[i]->flags & ARG_MAN_ALIAS_OPT))
return opt_names_alpha[i]->short_opt; /* alias for man only */
#endif
if ((!p && !(opt_names_alpha[i]->flags & ARG_LONG_OPT)) ||
(p && !opt_names_alpha[i]->short_opt))
return opt_names_alpha[i]->opt_enum; /* Found */
@ -268,6 +272,10 @@ static int _opt_str_to_num(struct command *cmd, const char *str)
for (i = middle + 1; i <= last; ++i) {
if (strcmp(opt_names_alpha[i]->long_opt, long_name))
break;
#ifndef MAN_PAGE_GENERATOR
if (!p && (opt_names_alpha[i]->flags & ARG_MAN_ALIAS_OPT))
return opt_names_alpha[i]->short_opt; /* alias for man only */
#endif
if ((!p && !(opt_names_alpha[i]->flags & ARG_LONG_OPT)) ||
(p && !opt_names_alpha[i]->short_opt))
return opt_names_alpha[i]->opt_enum; /* Found */

View File

@ -227,9 +227,9 @@ struct command {
struct opt_name {
const char *desc;
const char long_opt[27];/* --foo */
const char short_opt; /* -f */
uint16_t opt_enum; /* foo_ARG */
const char long_opt[26];/* --foo */
uint16_t short_opt; /* -f */
uint16_t opt_enum; /* foo_ARG */
uint16_t val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
uint16_t flags;
uint16_t prio;

View File

@ -61,6 +61,7 @@ static void *dm_pool_alloc(void *p, size_t size)
#define ARG_GROUPABLE 0x00000002
#define ARG_NONINTERACTIVE 0x00000004
#define ARG_LONG_OPT 0x00000008
#define ARG_MAN_ALIAS_OPT 0x00000010
struct arg_values;
/* needed to include vals.h */
@ -350,6 +351,11 @@ static void _print_man_option(const char *name, int opt_enum, int indent)
{
int short_opt = opt_names[opt_enum].short_opt;
if (opt_names[opt_enum].flags & ARG_MAN_ALIAS_OPT) {
opt_enum = short_opt;
short_opt = opt_names[short_opt].short_opt;
}
if (short_opt)
printf("\\fB-%c\\fP|", short_opt);
else if (indent)

View File

@ -62,6 +62,7 @@
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
#define ARG_NONINTERACTIVE 0x00000004 /* only for use in noninteractive mode */
#define ARG_LONG_OPT 0x00000008 /* arg has long format option */
#define ARG_MAN_ALIAS_OPT 0x00000010 /* option is a man alias for another option */
struct arg_values {
char *value;