tree-wide: add a helper to parse boolean optarg
This nicely covers the case when optarg is optional. The same parser can be used when the option string passed to getopt_long() requires a parameter and when it doesn't. The error messages are made consistent. Also fixes a log error c&p in --crash-reboot message.
This commit is contained in:
+11
-20
@@ -2473,27 +2473,22 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_EXPECT_REPLY:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--expect-reply=", optarg, &arg_expect_reply);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --expect-reply= parameter '%s': %m", optarg);
|
||||
|
||||
arg_expect_reply = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_AUTO_START:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--auto-start=", optarg, &arg_auto_start);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --auto-start= parameter '%s': %m", optarg);
|
||||
|
||||
arg_auto_start = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_ALLOW_INTERACTIVE_AUTHORIZATION:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--allow-interactive-authorization=", optarg,
|
||||
&arg_allow_interactive_authorization);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --allow-interactive-authorization= parameter '%s': %m", optarg);
|
||||
|
||||
arg_allow_interactive_authorization = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_TIMEOUT:
|
||||
@@ -2504,19 +2499,15 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_AUGMENT_CREDS:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--augment-creds=", optarg, &arg_augment_creds);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --augment-creds= parameter '%s': %m", optarg);
|
||||
|
||||
arg_augment_creds = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_WATCH_BIND:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--watch-bind=", optarg, &arg_watch_bind);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --watch-bind= parameter '%s': %m", optarg);
|
||||
|
||||
arg_watch_bind = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
|
||||
Reference in New Issue
Block a user