enum { OPT_LOGFILE, OPT_VERBOSE };
char *logfile; // options to be set
bool verbose;
static nng_optspec specs[] = {
{
.o_name = "logfile",
.o_short = 'D',
.o_val = OPT_LOGFILE,
.o_arg = true,
}, {
.o_name = "verbose",
.o_short = 'V',
.o_val = OPT_VERBOSE,
.o_arg = false,
}, {
.o_val = 0; // Terminate array
}
};
for (int idx = 1;;) {
int rv, opt;
char *arg;
rv = nng_opts_parse(argc, argv, specs, &opt, &arg, &idx);
if (rv != 0) {
break;
}
switch (opt) {
case OPT_LOGFILE:
logfile = arg;
break;
case OPT_VERBOSE:
verbose = true;
break;
}
}
if (rv != -1) {
printf("Options error: %s\n", nng_strerror(rv));
exit(1);
}