Merge pull request #11 from sbc100/exit_code_on_bad_option

Exit with non-zero status on bad command line option
This commit is contained in:
robertswiecki 2017-02-16 02:44:50 +01:00 committed by GitHub
commit 1b06c6f685

View File

@ -54,7 +54,7 @@ static const char *logYesNo(bool yes)
return (yes ? "true" : "false"); return (yes ? "true" : "false");
} }
static void cmdlineHelp(const char *pname, struct custom_option *opts) static void cmdlineUsage(const char *pname, struct custom_option *opts)
{ {
LOG_HELP_BOLD("Usage: %s [options] -- path_to_command [args]", pname); LOG_HELP_BOLD("Usage: %s [options] -- path_to_command [args]", pname);
LOG_HELP_BOLD("Options:"); LOG_HELP_BOLD("Options:");
@ -145,12 +145,6 @@ void cmdlineLogParams(struct nsjconf_t *nsjconf)
} }
} }
static void cmdlineUsage(const char *pname, struct custom_option *opts)
{
cmdlineHelp(pname, opts);
exit(0);
}
static bool cmdlineIsANumber(const char *s) static bool cmdlineIsANumber(const char *s)
{ {
for (int i = 0; s[i]; s++) { for (int i = 0; s[i]; s++) {
@ -495,8 +489,8 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
nsjconf->tlimit = strtol(optarg, NULL, 0); nsjconf->tlimit = strtol(optarg, NULL, 0);
break; break;
case 'h': /* help */ case 'h': /* help */
case '?': /* help */
cmdlineUsage(argv[0], custom_opts); cmdlineUsage(argv[0], custom_opts);
exit(0);
break; break;
case 0x0201: case 0x0201:
nsjconf->rl_as = cmdlineParseRLimit(RLIMIT_AS, optarg, (1024 * 1024)); nsjconf->rl_as = cmdlineParseRLimit(RLIMIT_AS, optarg, (1024 * 1024));