#include "process-util.h"
#include "set.h"
#include "static-destruct.h"
+#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "udevadm.h"
SCAN_TYPE_DEVICES,
SCAN_TYPE_SUBSYSTEMS,
SCAN_TYPE_ALL,
+ _SCAN_TYPE_MAX,
+ _SCAN_TYPE_INVALID = -EINVAL,
} ScanType;
static bool arg_verbose = false;
STATIC_DESTRUCTOR_REGISTER(arg_tag_match, strv_freep);
STATIC_DESTRUCTOR_REGISTER(arg_prioritized_subsystems, strv_freep);
+static const char *scan_type_table[_SCAN_TYPE_MAX] = {
+ [SCAN_TYPE_DEVICES] = "devices",
+ [SCAN_TYPE_SUBSYSTEMS] = "subsystems",
+ [SCAN_TYPE_ALL] = "all",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(scan_type, ScanType);
+
static int exec_list(
sd_device_enumerator *e,
sd_device_action_t action,
break;
case 't':
- if (streq(optarg, "devices"))
- arg_scan_type = SCAN_TYPE_DEVICES;
- else if (streq(optarg, "subsystems"))
- arg_scan_type = SCAN_TYPE_SUBSYSTEMS;
- else if (streq(optarg, "all"))
- arg_scan_type = SCAN_TYPE_ALL;
- else
+ arg_scan_type = scan_type_from_string(optarg);
+ if (arg_scan_type < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg);
break;