mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +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:
@@ -19,6 +19,7 @@ CLI_TEST_COMMON_OBJS := \
|
|||||||
common/msg_queue.o \
|
common/msg_queue.o \
|
||||||
common/setup.o \
|
common/setup.o \
|
||||||
common/utils.o \
|
common/utils.o \
|
||||||
|
common/version.o \
|
||||||
common/type_to_string.o \
|
common/type_to_string.o \
|
||||||
common/permute_tx.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 */
|
/* Generated stub for towire_node_id */
|
||||||
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
|
{ 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 */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED)
|
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 */
|
/* Generated stub for towire_node_id */
|
||||||
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
|
{ 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 */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED)
|
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 */
|
/* Generated stub for towire_node_id */
|
||||||
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
|
{ 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 */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED)
|
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)
|
#define OPT_MULTI (1 << OPT_USER_START)
|
||||||
/* Set if developer-only */
|
/* Set if developer-only */
|
||||||
#define OPT_DEV (1 << (OPT_USER_START+1))
|
#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) \
|
#define clnopt_witharg(names, type, cb, show, arg, desc) \
|
||||||
_opt_register((names), \
|
_opt_register((names), \
|
||||||
OPT_CB_ARG((cb), (type), (show), (arg)), \
|
OPT_CB_ARG((cb), (type), (show), (arg)), \
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <ccan/compiler/compiler.h>
|
#include <ccan/compiler/compiler.h>
|
||||||
|
#include <common/configvar.h>
|
||||||
#include <common/version.h>
|
#include <common/version.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -13,7 +14,7 @@ const char *version(void)
|
|||||||
return VERSION;
|
return VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *version_and_exit(const void *unused UNUSED)
|
static char *version_and_exit(const void *unused UNUSED)
|
||||||
{
|
{
|
||||||
printf("%s\n", VERSION);
|
printf("%s\n", VERSION);
|
||||||
if (BUILD_FEATURES[0]) {
|
if (BUILD_FEATURES[0]) {
|
||||||
@@ -22,6 +23,13 @@ char *version_and_exit(const void *unused UNUSED)
|
|||||||
exit(0);
|
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) {
|
static bool cmp_release_version(const char *version) {
|
||||||
if (version[0] != 'v')
|
if (version[0] != 'v')
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
char *version_and_exit(const void *unused);
|
/* Add --version|-V option */
|
||||||
|
void opt_register_version(void);
|
||||||
|
|
||||||
const char *version(void);
|
const char *version(void);
|
||||||
/* check if the current version is a release version.
|
/* check if the current version is a release version.
|
||||||
*
|
*
|
||||||
* Released versions are of form v[year].[month]?(.patch)* */
|
* Released versions are of form v[year].[month]?(.patch)* */
|
||||||
bool is_released_version(void);
|
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 */
|
#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)
|
static void register_opts(struct lightningd *ld)
|
||||||
{
|
{
|
||||||
/* This happens before plugins started */
|
/* This happens before plugins started */
|
||||||
opt_register_early_noarg("--test-daemons-only",
|
clnopt_noarg("--test-daemons-only", OPT_EARLY|OPT_EXITS,
|
||||||
test_subdaemons_and_exit,
|
test_subdaemons_and_exit,
|
||||||
ld, opt_hidden);
|
ld,
|
||||||
|
"Test that subdaemons can be run, then exit immediately");
|
||||||
/* Register plugins as an early args, so we can initialize them and have
|
/* Register plugins as an early args, so we can initialize them and have
|
||||||
* them register more command line options */
|
* them register more command line options */
|
||||||
clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY,
|
clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY,
|
||||||
@@ -1283,8 +1284,8 @@ static void register_opts(struct lightningd *ld)
|
|||||||
opt_set_announce_dns, NULL,
|
opt_set_announce_dns, NULL,
|
||||||
ld, opt_hidden);
|
ld, opt_hidden);
|
||||||
|
|
||||||
opt_register_noarg("--help|-h", opt_lightningd_usage, ld,
|
clnopt_noarg("--help|-h", OPT_EXITS,
|
||||||
"Print this message.");
|
opt_lightningd_usage, ld, "Print this message.");
|
||||||
opt_register_arg("--rgb", opt_set_rgb, opt_show_rgb, ld,
|
opt_register_arg("--rgb", opt_set_rgb, opt_show_rgb, ld,
|
||||||
"RRGGBB hex color for node");
|
"RRGGBB hex color for node");
|
||||||
opt_register_arg("--alias", opt_set_alias, opt_show_alias, ld,
|
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();
|
setup_option_allocators();
|
||||||
|
|
||||||
/*~ List features immediately, before doing anything interesting */
|
/*~ List features immediately, before doing anything interesting */
|
||||||
opt_register_early_noarg("--list-features-only",
|
clnopt_noarg("--list-features-only", OPT_EARLY|OPT_EXITS,
|
||||||
list_features_and_exit,
|
list_features_and_exit,
|
||||||
ld, opt_hidden);
|
ld, "List the features configured, and exit immediately");
|
||||||
|
|
||||||
/*~ This does enough parsing to get us the base configuration options */
|
/*~ This does enough parsing to get us the base configuration options */
|
||||||
ld->configvars = initial_config_opts(ld, &argc, argv, true,
|
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)
|
if (opt->type & OPT_DEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (opt->type & OPT_NOARG) {
|
/* Ignore things which just exit */
|
||||||
if (opt->desc == opt_hidden) {
|
if (opt->type & OPT_EXITS)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Ignore hidden options (deprecated) */
|
/* Ignore hidden options (deprecated) */
|
||||||
} else if (opt->cb == (void *)opt_usage_and_exit
|
if (opt->desc == opt_hidden)
|
||||||
|| opt->cb == (void *)version_and_exit
|
return;
|
||||||
|| is_restricted_ignored(opt->cb)
|
|
||||||
|| opt->cb == (void *)opt_lightningd_usage
|
if (opt->type & OPT_NOARG) {
|
||||||
|| opt->cb == (void *)test_subdaemons_and_exit
|
if (opt->cb == (void *)opt_clear_plugins) {
|
||||||
/* FIXME: we can't recover this. */
|
/* FIXME: we can't recover this. */
|
||||||
|| opt->cb == (void *)opt_clear_plugins) {
|
} else if (is_restricted_ignored(opt->cb)) {
|
||||||
/* These are not important */
|
/* --testnet etc, turned into --network=. */
|
||||||
} else if (opt->cb == (void *)opt_set_bool) {
|
} else if (opt->cb == (void *)opt_set_bool) {
|
||||||
const bool *b = opt->u.carg;
|
const bool *b = opt->u.carg;
|
||||||
json_add_bool(response, name0, *b);
|
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);
|
errx(1, "Unknown decode for %s", opt->names);
|
||||||
}
|
}
|
||||||
} else if (opt->type & OPT_HASARG) {
|
} else if (opt->type & OPT_HASARG) {
|
||||||
if (opt->desc == opt_hidden) {
|
if (opt->show == (void *)opt_show_charp) {
|
||||||
/* Ignore hidden options (deprecated) */
|
|
||||||
} else if (opt->show == (void *)opt_show_charp) {
|
|
||||||
if (*(char **)opt->u.carg)
|
if (*(char **)opt->u.carg)
|
||||||
/* Don't truncate or quote! */
|
/* Don't truncate or quote! */
|
||||||
answer = tal_strdup(tmpctx,
|
answer = tal_strdup(tmpctx,
|
||||||
|
|||||||
Reference in New Issue
Block a user