mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
lightningd: use OPT_EXITS for options which exit.
Clearly, listconfigs shouldn't list these. Also, hoist the opt_hidden check since it's independent of whether there's an arg or not. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
de148febb1
commit
86abb4c4bd
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)), \
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "config.h"
|
||||
#include <ccan/compiler/compiler.h>
|
||||
#include <common/configvar.h>
|
||||
#include <common/version.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -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;
|
||||
|
@ -3,15 +3,14 @@
|
||||
#include "config.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
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 */
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user