Help: use an array to choose which help matches which mode.

Looks cleaner than a big switch statement.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2012-07-09 17:14:16 +10:00
parent 7d27d1c091
commit 5187a38587
3 changed files with 17 additions and 11 deletions

View File

@ -600,3 +600,14 @@ char Help_config[] =
"\n"
;
char *mode_help[mode_count] = {
[0] = Help,
[ASSEMBLE] = Help_assemble,
[BUILD] = Help_build,
[CREATE] = Help_create,
[MANAGE] = Help_manage,
[MISC] = Help_misc,
[MONITOR] = Help_monitor,
[GROW] = Help_grow,
[INCREMENTAL] = Help_incr,
};

15
mdadm.c
View File

@ -1136,20 +1136,13 @@ int main(int argc, char *argv[])
}
if (print_help) {
char *help_text = Help;
char *help_text;
if (print_help == 2)
help_text = OptionHelp;
else
switch (mode) {
case ASSEMBLE : help_text = Help_assemble; break;
case BUILD : help_text = Help_build; break;
case CREATE : help_text = Help_create; break;
case MANAGE : help_text = Help_manage; break;
case MISC : help_text = Help_misc; break;
case MONITOR : help_text = Help_monitor; break;
case GROW : help_text = Help_grow; break;
case INCREMENTAL:help_text= Help_incr; break;
}
help_text = mode_help[mode];
if (help_text == NULL)
help_text = Help;
fputs(help_text,stdout);
exit(0);
}

View File

@ -264,6 +264,7 @@ enum mode {
GROW,
INCREMENTAL,
AUTODETECT,
mode_count
};
extern char short_options[];
@ -271,6 +272,7 @@ extern char short_bitmap_options[];
extern char short_bitmap_auto_options[];
extern struct option long_options[];
extern char Version[], Usage[], Help[], OptionHelp[],
*mode_help[],
Help_create[], Help_build[], Help_assemble[], Help_grow[],
Help_incr[],
Help_manage[], Help_misc[], Help_monitor[], Help_config[];