Skip to content

eBPF-based security platform

help: name a help section's items once, with HELP_ITEMS()

Daniel Borkmannec232d6293a6
diff --git a/builtin-attest.c b/builtin-attest.c
index b81ac1c1..6ba83738 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -96,15 +96,11 @@ static const struct help_item predict_options[] = {
};
static const struct help_section attest_help_sections[] = {
- { "subcommands:", attest_subcmds, ARRAY_SIZE(attest_subcmds) },
- { "evidence options (target):", attest_options,
- ARRAY_SIZE(attest_options) },
- { "verify options (operator):", verify_options,
- ARRAY_SIZE(verify_options) },
- { "predict options (operator):", predict_options,
- ARRAY_SIZE(predict_options) },
- { "challenge options (operator):", challenge_options,
- ARRAY_SIZE(challenge_options) },
+ HELP_ITEMS("subcommands:", attest_subcmds),
+ HELP_ITEMS("evidence options (target):", attest_options),
+ HELP_ITEMS("verify options (operator):", verify_options),
+ HELP_ITEMS("predict options (operator):", predict_options),
+ HELP_ITEMS("challenge options (operator):", challenge_options),
};
static const struct help attest_help = {
diff --git a/builtin-bpm.c b/builtin-bpm.c
index c49bf851..1507d9d7 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -2736,7 +2736,7 @@ static const struct help bpm_target_help = {
.usage = "shirudo bpm <config|repo|tree|key|pull|info|install|upgrade|list|uninstall>",
.summary = "Manage signed target-local BPM packages backed by OCI repositories.",
.sections = (const struct help_section[]) {
- { "subcommands:", bpm_target_subcmds, ARRAY_SIZE(bpm_target_subcmds) },
+ HELP_ITEMS("subcommands:", bpm_target_subcmds),
},
.n_sections = 1,
};
@@ -2745,7 +2745,7 @@ static const struct help bpm_operator_help = {
.usage = "shirudo bpm <config|repo|tree|key|pull|info|push|build|install|upgrade|list|uninstall>",
.summary = "Manage signed OCI packages and publish packages from the operator.",
.sections = (const struct help_section[]) {
- { "subcommands:", bpm_subcmds, ARRAY_SIZE(bpm_subcmds) },
+ HELP_ITEMS("subcommands:", bpm_subcmds),
},
.n_sections = 1,
};
@@ -2796,7 +2796,7 @@ static const struct help bpm_key_help = {
.usage = "shirudo bpm key <add|fingerprint|list>",
.summary = "Manage package signing certificates.",
.sections = (const struct help_section[]) {
- { "subcommands:", bpm_key_subcmds, ARRAY_SIZE(bpm_key_subcmds) },
+ HELP_ITEMS("subcommands:", bpm_key_subcmds),
},
.n_sections = 1,
.footer = "add and fingerprint accept a certificate file, .bee package, or\n"
diff --git a/builtin-genkey.c b/builtin-genkey.c
index d657c7c4..e9c74906 100644
--- a/builtin-genkey.c
+++ b/builtin-genkey.c
@@ -376,8 +376,7 @@ static const struct help_item genkey_options[] = {
};
static const struct help_section genkey_help_sections[] = {
- { "options:", genkey_options,
- ARRAY_SIZE(genkey_options) },
+ HELP_ITEMS("options:", genkey_options),
};
static const struct help genkey_help = {
diff --git a/builtin-init.c b/builtin-init.c
index b05b18e7..ea6dd4bf 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -1334,8 +1334,7 @@ static const struct help_item init_options[] = {
};
static const struct help_section init_help_sections[] = {
- { "options:", init_options,
- ARRAY_SIZE(init_options) },
+ HELP_ITEMS("options:", init_options),
};
static const struct help init_help = {
diff --git a/builtin-keys.c b/builtin-keys.c
index 4b23f800..ada2cb6d 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -495,9 +495,8 @@ static const struct help_item keys_options[] = {
};
static const struct help_section keys_help_sections[] = {
- { "subcommands:", keys_subcmds, ARRAY_SIZE(keys_subcmds) },
- { "options:", keys_options,
- ARRAY_SIZE(keys_options) },
+ HELP_ITEMS("subcommands:", keys_subcmds),
+ HELP_ITEMS("options:", keys_options),
};
static const struct help keys_help = {
@@ -529,7 +528,7 @@ static const struct help_item keys_add_options[] = {
};
static const struct help_section keys_add_sections[] = {
- { "options:", keys_add_options, ARRAY_SIZE(keys_add_options) },
+ HELP_ITEMS("options:", keys_add_options),
};
static const struct help keys_add_help = {
@@ -550,7 +549,7 @@ static const struct help_item keys_vouch_options[] = {
};
static const struct help_section keys_vouch_sections[] = {
- { "options:", keys_vouch_options, ARRAY_SIZE(keys_vouch_options) },
+ HELP_ITEMS("options:", keys_vouch_options),
};
static const struct help keys_vouch_help = {
diff --git a/builtin-status.c b/builtin-status.c
index 66214165..0b4f0981 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -368,8 +368,7 @@ static const struct help_item status_options[] = {
};
static const struct help_section status_help_sections[] = {
- { "options:", status_options,
- ARRAY_SIZE(status_options) },
+ HELP_ITEMS("options:", status_options),
};
static const struct help status_help = {
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 081173b1..36241a26 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -230,7 +230,7 @@ static const struct help_item upatch_map_options[] = {
};
static const struct help_section upatch_map_sections[] = {
- { "options:", upatch_map_options, ARRAY_SIZE(upatch_map_options) },
+ HELP_ITEMS("options:", upatch_map_options),
};
static const struct help upatch_map_help = {
@@ -273,7 +273,7 @@ static const struct help_item upatch_get_options[] = {
};
static const struct help_section upatch_get_sections[] = {
- { "options:", upatch_get_options, ARRAY_SIZE(upatch_get_options) },
+ HELP_ITEMS("options:", upatch_get_options),
};
static const struct help upatch_get_help = {
@@ -4663,8 +4663,7 @@ static const struct help_item upatch_subcmds[] = {
};
static const struct help_section upatch_help_sections[] = {
- { "subcommands:", upatch_subcmds,
- ARRAY_SIZE(upatch_subcmds) },
+ HELP_ITEMS("subcommands:", upatch_subcmds),
};
static const struct help upatch_help = {
diff --git a/builtin-version.c b/builtin-version.c
index 8aedbab1..c908227a 100644
--- a/builtin-version.c
+++ b/builtin-version.c
@@ -19,8 +19,7 @@ static const struct help_item version_options[] = {
};
static const struct help_section version_help_sections[] = {
- { "options:", version_options,
- ARRAY_SIZE(version_options) },
+ HELP_ITEMS("options:", version_options),
};
static const struct help version_help = {
diff --git a/util/help.h b/util/help.h
index 5e7c5818..48d7de8d 100644
--- a/util/help.h
+++ b/util/help.h
@@ -12,6 +12,8 @@
#include <string.h>
#include <stddef.h>
+#include <shirudo/misc.h>
+
struct help_item {
const char *name;
const char *summary;
@@ -23,6 +25,11 @@ struct help_section {
size_t n_items;
};
+/* A section named h listing the items of the array a. */
+#define HELP_ITEMS(h, a) \
+ { .header = (h), .items = (a), \
+ .n_items = sizeof(a) / sizeof((a)[0]) + __must_be_array(a) }
+
struct help {
const char *usage;
const char *summary;