diff --git a/cli/test/Makefile b/cli/test/Makefile index de38487ed..d06cfe247 100644 --- a/cli/test/Makefile +++ b/cli/test/Makefile @@ -19,6 +19,7 @@ CLI_TEST_COMMON_OBJS := \ common/msg_queue.o \ common/setup.o \ common/utils.o \ + common/version.o \ common/type_to_string.o \ common/permute_tx.o diff --git a/cli/test/run-human-mode.c b/cli/test/run-human-mode.c index d71303ff7..9e5f0bed2 100644 --- a/cli/test/run-human-mode.c +++ b/cli/test/run-human-mode.c @@ -107,9 +107,6 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U /* Generated stub for towire_node_id */ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) { fprintf(stderr, "towire_node_id called!\n"); abort(); } -/* Generated stub for version_and_exit */ -char *version_and_exit(const void *unused UNNEEDED) -{ fprintf(stderr, "version_and_exit called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED) diff --git a/cli/test/run-large-input.c b/cli/test/run-large-input.c index aee9bee5c..0e0dc5494 100644 --- a/cli/test/run-large-input.c +++ b/cli/test/run-large-input.c @@ -107,9 +107,6 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U /* Generated stub for towire_node_id */ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) { fprintf(stderr, "towire_node_id called!\n"); abort(); } -/* Generated stub for version_and_exit */ -char *version_and_exit(const void *unused UNNEEDED) -{ fprintf(stderr, "version_and_exit called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED) diff --git a/cli/test/run-remove-hint.c b/cli/test/run-remove-hint.c index f081ec79f..5811b0fbb 100644 --- a/cli/test/run-remove-hint.c +++ b/cli/test/run-remove-hint.c @@ -110,9 +110,6 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U /* Generated stub for towire_node_id */ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) { fprintf(stderr, "towire_node_id called!\n"); abort(); } -/* Generated stub for version_and_exit */ -char *version_and_exit(const void *unused UNNEEDED) -{ fprintf(stderr, "version_and_exit called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED) diff --git a/common/configvar.h b/common/configvar.h index fc126e8f2..8deceedc7 100644 --- a/common/configvar.h +++ b/common/configvar.h @@ -50,8 +50,10 @@ struct configvar { #define OPT_MULTI (1 << OPT_USER_START) /* Set if developer-only */ #define OPT_DEV (1 << (OPT_USER_START+1)) +/* Doesn't return, so don't show in listconfigs */ +#define OPT_EXITS (1 << (OPT_USER_START+2)) -/* Use this instead of opt_register_*_arg if you want OPT_MULTI/OPT_DEV */ +/* Use this instead of opt_register_*_arg if you want OPT_* from above */ #define clnopt_witharg(names, type, cb, show, arg, desc) \ _opt_register((names), \ OPT_CB_ARG((cb), (type), (show), (arg)), \ diff --git a/common/version.c b/common/version.c index 4fc20b666..0840968fd 100644 --- a/common/version.c +++ b/common/version.c @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include #include #include @@ -13,7 +14,7 @@ const char *version(void) return VERSION; } -char *version_and_exit(const void *unused UNUSED) +static char *version_and_exit(const void *unused UNUSED) { printf("%s\n", VERSION); if (BUILD_FEATURES[0]) { @@ -22,6 +23,13 @@ char *version_and_exit(const void *unused UNUSED) exit(0); } +void opt_register_version(void) +{ + clnopt_noarg("--version|-V", OPT_EARLY|OPT_EXITS, + version_and_exit, NULL, + "Print version and exit"); +} + static bool cmp_release_version(const char *version) { if (version[0] != 'v') return false; diff --git a/common/version.h b/common/version.h index 90b7c824d..aebc002ed 100644 --- a/common/version.h +++ b/common/version.h @@ -3,15 +3,14 @@ #include "config.h" #include -char *version_and_exit(const void *unused); +/* Add --version|-V option */ +void opt_register_version(void); + const char *version(void); /* check if the current version is a release version. * * Released versions are of form v[year].[month]?(.patch)* */ bool is_released_version(void); -#define opt_register_version() \ - opt_register_early_noarg("--version|-V", version_and_exit, NULL, \ - "Print version and exit") #endif /* LIGHTNING_COMMON_VERSION_H */ diff --git a/lightningd/options.c b/lightningd/options.c index b45265aeb..ddf2ca9a1 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -1212,9 +1212,10 @@ static char *opt_set_announce_dns(const char *optarg, struct lightningd *ld) static void register_opts(struct lightningd *ld) { /* This happens before plugins started */ - opt_register_early_noarg("--test-daemons-only", - test_subdaemons_and_exit, - ld, opt_hidden); + clnopt_noarg("--test-daemons-only", OPT_EARLY|OPT_EXITS, + test_subdaemons_and_exit, + ld, + "Test that subdaemons can be run, then exit immediately"); /* Register plugins as an early args, so we can initialize them and have * them register more command line options */ clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY, @@ -1283,8 +1284,8 @@ static void register_opts(struct lightningd *ld) opt_set_announce_dns, NULL, ld, opt_hidden); - opt_register_noarg("--help|-h", opt_lightningd_usage, ld, - "Print this message."); + clnopt_noarg("--help|-h", OPT_EXITS, + opt_lightningd_usage, ld, "Print this message."); opt_register_arg("--rgb", opt_set_rgb, opt_show_rgb, ld, "RRGGBB hex color for node"); opt_register_arg("--alias", opt_set_alias, opt_show_alias, ld, @@ -1550,9 +1551,9 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[]) setup_option_allocators(); /*~ List features immediately, before doing anything interesting */ - opt_register_early_noarg("--list-features-only", - list_features_and_exit, - ld, opt_hidden); + clnopt_noarg("--list-features-only", OPT_EARLY|OPT_EXITS, + list_features_and_exit, + ld, "List the features configured, and exit immediately"); /*~ This does enough parsing to get us the base configuration options */ ld->configvars = initial_config_opts(ld, &argc, argv, true, @@ -1710,17 +1711,19 @@ static void add_config(struct lightningd *ld, if (opt->type & OPT_DEV) return; + /* Ignore things which just exit */ + if (opt->type & OPT_EXITS) + return; + + /* Ignore hidden options (deprecated) */ + if (opt->desc == opt_hidden) + return; + if (opt->type & OPT_NOARG) { - if (opt->desc == opt_hidden) { - /* Ignore hidden options (deprecated) */ - } else if (opt->cb == (void *)opt_usage_and_exit - || opt->cb == (void *)version_and_exit - || is_restricted_ignored(opt->cb) - || opt->cb == (void *)opt_lightningd_usage - || opt->cb == (void *)test_subdaemons_and_exit - /* FIXME: we can't recover this. */ - || opt->cb == (void *)opt_clear_plugins) { - /* These are not important */ + if (opt->cb == (void *)opt_clear_plugins) { + /* FIXME: we can't recover this. */ + } else if (is_restricted_ignored(opt->cb)) { + /* --testnet etc, turned into --network=. */ } else if (opt->cb == (void *)opt_set_bool) { const bool *b = opt->u.carg; json_add_bool(response, name0, *b); @@ -1775,9 +1778,7 @@ static void add_config(struct lightningd *ld, errx(1, "Unknown decode for %s", opt->names); } } else if (opt->type & OPT_HASARG) { - if (opt->desc == opt_hidden) { - /* Ignore hidden options (deprecated) */ - } else if (opt->show == (void *)opt_show_charp) { + if (opt->show == (void *)opt_show_charp) { if (*(char **)opt->u.carg) /* Don't truncate or quote! */ answer = tal_strdup(tmpctx,