Print list of supported options. Signed-off-by: Florian Westphal <fw@xxxxxxxxx> --- src/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.c b/src/main.c index 6e14a7f26b0f..cf00f27f06de 100644 --- a/src/main.c +++ b/src/main.c @@ -86,6 +86,7 @@ enum opt_vals { enum optimization_feature { OPTIMIZE_UNDEFINED, + OPTIMIZE_HELP, OPTIMIZE_REMOVE_DEPENDENCIES, }; @@ -315,11 +316,18 @@ static const struct { static const struct { const char *name; + const char *help; enum optimization_feature level; enum nft_optimization_flags flag; } optimization_param[] = { + { + .name = "help", + .help = "", + .level = OPTIMIZE_HELP, + }, { .name = "remove-dependencies", + .help = "ruleset listing with redundant expressions removed", .level = OPTIMIZE_REMOVE_DEPENDENCIES, .flag = NFT_OPTIMIZATION_F_REMOVE_DEPS, }, @@ -372,6 +380,7 @@ static bool nft_options_check(int argc, char * const argv[]) static void optimize_settings_set_custom(struct nft_ctx *ctx, char *options) { + unsigned int default_flags = ctx->optimization_flags; unsigned int i; char *end; @@ -401,7 +410,21 @@ static void optimize_settings_set_custom(struct nft_ctx *ctx, char *options) switch (level) { case OPTIMIZE_UNDEFINED: fprintf(stderr, "invalid optimization option `%s'\n", options); + fprintf(stderr, "Try \"-O help\" for list of options.\n"); exit(EXIT_FAILURE); + case OPTIMIZE_HELP: + for (i = 0; i < array_size(optimization_param); i++) { + if (level == optimization_param[i].level) + continue; + + flag = optimization_param[i].flag; + printf("%s: %s (default %s)\n", + optimization_param[i].name, optimization_param[i].help, + default_flags & flag ? "on" : "off"); + } + + printf("\nPrepend \"no-\" to disable options that are enabled by default.\n"); + exit(EXIT_SUCCESS); case OPTIMIZE_REMOVE_DEPENDENCIES: break; } -- 2.26.3