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:
@@ -23,6 +23,7 @@
|
||||
#include "missing_network.h"
|
||||
#include "netlink-util.h"
|
||||
#include "pager.h"
|
||||
#include "parse-argument.h"
|
||||
#include "parse-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "resolvconf-compat.h"
|
||||
@@ -2766,11 +2767,9 @@ static int compat_parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_LEGEND:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--legend=", optarg, &arg_legend);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --legend= argument");
|
||||
|
||||
arg_legend = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
@@ -3062,11 +3061,9 @@ static int native_parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_LEGEND:
|
||||
r = parse_boolean(optarg);
|
||||
r = parse_boolean_argument("--legend=", optarg, &arg_legend);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --legend= argument");
|
||||
|
||||
arg_legend = r;
|
||||
return r;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
||||
Reference in New Issue
Block a user