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:
Rusty Russell
2023-06-02 12:06:04 +09:30
parent de148febb1
commit 86abb4c4bd
8 changed files with 38 additions and 36 deletions

View File

@@ -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)), \

View File

@@ -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;

View File

@@ -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 */