1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

Allow optional verbose logging.

This commit is contained in:
Alasdair Kergon 2003-01-21 21:25:51 +00:00
parent 39662e362a
commit a0568eca2b

View File

@ -30,6 +30,7 @@
enum { enum {
READ_ONLY = 0, READ_ONLY = 0,
MINOR_ARG, MINOR_ARG,
VERBOSE_ARG,
NUM_SWITCHES NUM_SWITCHES
}; };
@ -375,8 +376,8 @@ static int _deps(int argc, char **argv)
typedef int (*command_fn) (int argc, char **argv); typedef int (*command_fn) (int argc, char **argv);
struct command { struct command {
char *name; const char *name;
char *help; const char *help;
int min_args; int min_args;
int max_args; int max_args;
command_fn fn; command_fn fn;
@ -422,12 +423,13 @@ static struct command *_find_command(const char *name)
static int _process_switches(int *argc, char ***argv) static int _process_switches(int *argc, char ***argv)
{ {
int index; int ind;
int c; int c;
static struct option long_options[] = { static struct option long_options[] = {
{"read-only", 0, NULL, READ_ONLY}, {"read-only", 0, NULL, READ_ONLY},
{"minor", 1, NULL, MINOR_ARG}, {"minor", 1, NULL, MINOR_ARG},
{"verbose", 1, NULL, VERBOSE_ARG},
{"", 0, NULL, 0} {"", 0, NULL, 0}
}; };
@ -437,16 +439,20 @@ static int _process_switches(int *argc, char ***argv)
memset(&_switches, 0, sizeof(_switches)); memset(&_switches, 0, sizeof(_switches));
memset(&_values, 0, sizeof(_values)); memset(&_values, 0, sizeof(_values));
while ((c = getopt_long(*argc, *argv, "m:r", while ((c = getopt_long(*argc, *argv, "m:rv",
long_options, &index)) != -1) { long_options, &ind)) != -1) {
if (c == 'r' || index == READ_ONLY) if (c == 'r' || ind == READ_ONLY)
_switches[READ_ONLY]++; _switches[READ_ONLY]++;
if (c == 'm' || index == MINOR_ARG) { if (c == 'm' || ind == MINOR_ARG) {
_switches[MINOR_ARG]++; _switches[MINOR_ARG]++;
_values[MINOR_ARG] = atoi(optarg); _values[MINOR_ARG] = atoi(optarg);
} }
if (c == 'v' || ind == VERBOSE_ARG)
_switches[VERBOSE_ARG]++;
} }
dm_log_init_verbose(_switches[VERBOSE_ARG]);
*argv += optind; *argv += optind;
*argc -= optind; *argc -= optind;
return 1; return 1;