mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
opts: adds the autobool on/off/auto feature
This commit is contained in:
parent
e932f05bc8
commit
bd75f8ea6c
5 changed files with 46 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "config.h"
|
||||
#include <ccan/timer/timer.h>
|
||||
#include <common/node_id.h>
|
||||
#include <lightningd/options.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
/* We talk to `hsmd` to sign our gossip messages with the node key */
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
#include <lightningd/io_loop_with_timers.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/onchain_control.h>
|
||||
#include <lightningd/options.h>
|
||||
#include <lightningd/plugin.h>
|
||||
#include <lightningd/subd.h>
|
||||
#include <sys/resource.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "config.h"
|
||||
#include <lightningd/htlc_end.h>
|
||||
#include <lightningd/htlc_set.h>
|
||||
#include <lightningd/options.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -102,6 +102,41 @@ static char *opt_set_s32(const char *arg, s32 *u)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *opt_set_autobool_arg(const char *arg, enum opt_autobool *b)
|
||||
{
|
||||
if (!strcasecmp(arg, "yes") ||
|
||||
!strcasecmp(arg, "true")) {
|
||||
*b = OPT_AUTOBOOL_TRUE;
|
||||
return NULL;
|
||||
}
|
||||
if (!strcasecmp(arg, "no") ||
|
||||
!strcasecmp(arg, "false")) {
|
||||
*b = OPT_AUTOBOOL_FALSE;
|
||||
return NULL;
|
||||
}
|
||||
if (!strcasecmp(arg, "auto") ||
|
||||
!strcasecmp(arg, "default")) {
|
||||
*b = OPT_AUTOBOOL_AUTO;
|
||||
return NULL;
|
||||
}
|
||||
return opt_invalid_argument(arg);
|
||||
}
|
||||
|
||||
void opt_show_autobool(char buf[OPT_SHOW_LEN], const enum opt_autobool *b)
|
||||
{
|
||||
switch (*b) {
|
||||
case OPT_AUTOBOOL_TRUE:
|
||||
strncpy(buf, "true", OPT_SHOW_LEN);
|
||||
break;
|
||||
case OPT_AUTOBOOL_FALSE:
|
||||
strncpy(buf, "false", OPT_SHOW_LEN);
|
||||
break;
|
||||
case OPT_AUTOBOOL_AUTO:
|
||||
default:
|
||||
strncpy(buf, "auto", OPT_SHOW_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
static char *opt_set_mode(const char *arg, mode_t *m)
|
||||
{
|
||||
char *endp;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef LIGHTNING_LIGHTNINGD_OPTIONS_H
|
||||
#define LIGHTNING_LIGHTNINGD_OPTIONS_H
|
||||
#include "config.h"
|
||||
#include <ccan/ccan/opt/opt.h>
|
||||
|
||||
struct lightningd;
|
||||
|
||||
|
@ -13,4 +14,12 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[]);
|
|||
/* Derive default color and alias from the pubkey. */
|
||||
void setup_color_and_alias(struct lightningd *ld);
|
||||
|
||||
enum opt_autobool {
|
||||
OPT_AUTOBOOL_FALSE = 0,
|
||||
OPT_AUTOBOOL_TRUE = 1,
|
||||
OPT_AUTOBOOL_AUTO = 2,
|
||||
};
|
||||
char *opt_set_autobool_arg(const char *arg, enum opt_autobool *b);
|
||||
void opt_show_autobool(char buf[OPT_SHOW_LEN], const enum opt_autobool *b);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_OPTIONS_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue