mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
homectl: use table to parse --export-format=
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
#include "rlimit-util.h"
|
#include "rlimit-util.h"
|
||||||
#include "runtime-scope.h"
|
#include "runtime-scope.h"
|
||||||
#include "stat-util.h"
|
#include "stat-util.h"
|
||||||
|
#include "string-table.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "terminal-util.h"
|
#include "terminal-util.h"
|
||||||
@@ -69,6 +70,14 @@
|
|||||||
#include "userdb.h"
|
#include "userdb.h"
|
||||||
#include "verbs.h"
|
#include "verbs.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EXPORT_FORMAT_FULL, /* export the full record */
|
||||||
|
EXPORT_FORMAT_STRIPPED, /* strip "state" + "binding", but leave signature in place */
|
||||||
|
EXPORT_FORMAT_MINIMAL, /* also strip signature */
|
||||||
|
_EXPORT_FORMAT_MAX,
|
||||||
|
_EXPORT_FORMAT_INVALID = -EINVAL,
|
||||||
|
} ExportFormat;
|
||||||
|
|
||||||
static PagerFlags arg_pager_flags = 0;
|
static PagerFlags arg_pager_flags = 0;
|
||||||
static bool arg_legend = true;
|
static bool arg_legend = true;
|
||||||
static bool arg_ask_password = true;
|
static bool arg_ask_password = true;
|
||||||
@@ -97,11 +106,7 @@ static bool arg_recovery_key = false;
|
|||||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||||
static bool arg_and_resize = false;
|
static bool arg_and_resize = false;
|
||||||
static bool arg_and_change_password = false;
|
static bool arg_and_change_password = false;
|
||||||
static enum {
|
static ExportFormat arg_export_format = EXPORT_FORMAT_FULL;
|
||||||
EXPORT_FORMAT_FULL, /* export the full record */
|
|
||||||
EXPORT_FORMAT_STRIPPED, /* strip "state" + "binding", but leave signature in place */
|
|
||||||
EXPORT_FORMAT_MINIMAL, /* also strip signature */
|
|
||||||
} arg_export_format = EXPORT_FORMAT_FULL;
|
|
||||||
static uint64_t arg_capability_bounding_set = UINT64_MAX;
|
static uint64_t arg_capability_bounding_set = UINT64_MAX;
|
||||||
static uint64_t arg_capability_ambient_set = UINT64_MAX;
|
static uint64_t arg_capability_ambient_set = UINT64_MAX;
|
||||||
static char *arg_blob_dir = NULL;
|
static char *arg_blob_dir = NULL;
|
||||||
@@ -131,6 +136,14 @@ STATIC_DESTRUCTOR_REGISTER(arg_key_name, freep);
|
|||||||
|
|
||||||
static const BusLocator *bus_mgr;
|
static const BusLocator *bus_mgr;
|
||||||
|
|
||||||
|
static const char *export_format_table[_EXPORT_FORMAT_MAX] = {
|
||||||
|
[EXPORT_FORMAT_FULL] = "full",
|
||||||
|
[EXPORT_FORMAT_STRIPPED] = "stripped",
|
||||||
|
[EXPORT_FORMAT_MINIMAL] = "minimal",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(export_format, ExportFormat);
|
||||||
|
|
||||||
static bool identity_properties_specified(void) {
|
static bool identity_properties_specified(void) {
|
||||||
return
|
return
|
||||||
arg_identity ||
|
arg_identity ||
|
||||||
@@ -4732,18 +4745,12 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_EXPORT_FORMAT:
|
case ARG_EXPORT_FORMAT:
|
||||||
if (streq(optarg, "full"))
|
if (streq(optarg, "help"))
|
||||||
arg_export_format = EXPORT_FORMAT_FULL;
|
return DUMP_STRING_TABLE(export_format, ExportFormat, _EXPORT_FORMAT_MAX);
|
||||||
else if (streq(optarg, "stripped"))
|
|
||||||
arg_export_format = EXPORT_FORMAT_STRIPPED;
|
arg_export_format = export_format_from_string(optarg);
|
||||||
else if (streq(optarg, "minimal"))
|
if (arg_export_format < 0)
|
||||||
arg_export_format = EXPORT_FORMAT_MINIMAL;
|
return log_error_errno(arg_export_format, "Invalid export format: %s", optarg);
|
||||||
else if (streq(optarg, "help")) {
|
|
||||||
puts("full\n"
|
|
||||||
"stripped\n"
|
|
||||||
"minimal");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user