--help returns with exit-code 0 now. rc=1 when errors in option parsing.

This commit is contained in:
Manuel Domke
2018-02-26 14:09:50 +01:00
parent 88a8acf84f
commit a29e3c481f
2 changed files with 18 additions and 3 deletions

View File

@@ -187,7 +187,6 @@ static bool initializeUSB(struct ftdi_context *ftdic, char **message, char *seri
} else {
// serial specified
rc = ftdi_usb_open_desc(ftdic, INFNOISE_VENDOR_ID, INFNOISE_PRODUCT_ID, INFNOISE_DESCRIPTION, serial);
if (rc < 0) {
if(!isSuperUser()) {
*message = "Can't find Infinite Noise Multiplier. Try running as super user?\n";
@@ -241,7 +240,8 @@ static void initOpts(struct opt_struct *opts) {
opts->noOutput =
opts->listDevices =
opts->raw = false;
opts->help = false;
opts->none = false;
opts->pidFileName =
opts->serial = NULL;
}
@@ -299,7 +299,15 @@ int main(int argc, char **argv)
opts.daemon = true;
} else if(!strcmp(argv[xArg], "--list-devices")) {
opts.listDevices = true;
} else if(!strcmp(argv[xArg], "--help") || !strcmp(argv[xArg], "-h")) {
opts.help = true;
} else {
opts.help = true;
opts.none = true;
}
}
if (opts.help) {
fputs("Usage: infnoise [options]\n"
"Options are:\n"
" --debug - turn on some debug output\n"
@@ -311,11 +319,16 @@ int main(int argc, char **argv)
" --pidfile <file> - write process ID to file\n"
" --daemon - run in the background\n"
" --serial <serial> - use specified device\n"
" --list-devices - list available devices\n", stderr);
" --list-devices - list available devices\n"
" --help - this help output\n", stdout);
if (opts.none) {
return 1;
} else {
return 0;
}
}
// read environment variables, not overriding command line options
if (opts.serial == NULL) {
if (getenv("INFNOISE_SERIAL") != NULL) {

View File

@@ -38,6 +38,8 @@ struct opt_struct {
bool devRandom; // Feed /dev/random?
bool noOutput; // Supress output?
bool listDevices; // List possible USB-devices?
bool help; // Show help
bool none; // set to true when no valid arguments where detected
bool raw; // No whitening?
char *pidFileName; // Name of optional PID-file
char *serial; // Name of selected device