mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
common/configdir: simply supply defaults, leave parsing to programs.
We're going to get tricky with lightingd's parsing next, so split it out. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
875854f71c
commit
0b5b1faff5
4 changed files with 28 additions and 19 deletions
|
@ -392,12 +392,13 @@ int main(int argc, char *argv[])
|
|||
int fd, i;
|
||||
size_t off;
|
||||
const char *method;
|
||||
char *cmd, *resp, *idstr, *rpc_filename;
|
||||
char *cmd, *resp, *idstr;
|
||||
struct sockaddr_un addr;
|
||||
jsmntok_t *toks;
|
||||
const jsmntok_t *result, *error, *id;
|
||||
char *lightning_dir;
|
||||
const tal_t *ctx = tal(NULL, char);
|
||||
char *lightning_dir = default_configdir(ctx);
|
||||
char *rpc_filename = default_rpcfile(ctx);
|
||||
jsmn_parser parser;
|
||||
int parserr;
|
||||
enum format format = DEFAULT_FORMAT;
|
||||
|
@ -409,7 +410,14 @@ int main(int argc, char *argv[])
|
|||
jsmn_init(&parser);
|
||||
|
||||
opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
|
||||
configdir_register_opts(ctx, &lightning_dir, &rpc_filename);
|
||||
|
||||
opt_register_arg("--lightning-dir=<dir>", opt_set_talstr, opt_show_charp,
|
||||
&lightning_dir,
|
||||
"Set working directory. All other files are relative to this");
|
||||
|
||||
opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp,
|
||||
&rpc_filename,
|
||||
"Set JSON-RPC socket (or /dev/tty)");
|
||||
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<command> [<params>...]", "Show this message. Use the command help (without hyphens -- \"lightning-cli help\") to get a list of all RPC commands");
|
||||
|
|
|
@ -11,7 +11,7 @@ char *opt_set_talstr(const char *arg, char **p)
|
|||
return opt_set_charp(tal_strdup(NULL, arg), p);
|
||||
}
|
||||
|
||||
static char *default_configdir(const tal_t *ctx)
|
||||
char *default_configdir(const tal_t *ctx)
|
||||
{
|
||||
char *path;
|
||||
const char *env = getenv("HOME");
|
||||
|
@ -22,17 +22,7 @@ static char *default_configdir(const tal_t *ctx)
|
|||
return path;
|
||||
}
|
||||
|
||||
void configdir_register_opts(const tal_t *ctx,
|
||||
char **configdir, char **rpc_filename)
|
||||
char *default_rpcfile(const tal_t *ctx)
|
||||
{
|
||||
*configdir = default_configdir(ctx);
|
||||
*rpc_filename = tal_strdup(ctx, "lightning-rpc");
|
||||
|
||||
opt_register_early_arg("--lightning-dir=<dir>", opt_set_talstr, opt_show_charp,
|
||||
configdir,
|
||||
"Set working directory. All other files are relative to this");
|
||||
|
||||
opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp,
|
||||
rpc_filename,
|
||||
"Set JSON-RPC socket (or /dev/tty)");
|
||||
return tal_strdup(ctx, "lightning-rpc");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
/* Helper for options which are tal() strings. */
|
||||
char *opt_set_talstr(const char *arg, char **p);
|
||||
|
||||
void configdir_register_opts(const tal_t *ctx,
|
||||
char **config_dir, char **rpc_filename);
|
||||
/* The default configuration dir: ~/.lightning */
|
||||
char *default_configdir(const tal_t *ctx);
|
||||
|
||||
/* The default rpc filename: lightning-rpc */
|
||||
char *default_rpcfile(const tal_t *ctx);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_CONFIGDIR_H */
|
||||
|
|
|
@ -836,6 +836,10 @@ void register_opts(struct lightningd *ld)
|
|||
{
|
||||
opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
|
||||
|
||||
ld->rpc_filename = default_rpcfile(ld);
|
||||
opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp,
|
||||
&ld->rpc_filename,
|
||||
"Set JSON-RPC socket (or /dev/tty)");
|
||||
opt_register_noarg("--help|-h", opt_lightningd_usage, ld,
|
||||
"Print this message.");
|
||||
opt_register_early_noarg("--test-daemons-only",
|
||||
|
@ -878,7 +882,6 @@ void register_opts(struct lightningd *ld)
|
|||
opt_register_logging(ld);
|
||||
opt_register_version();
|
||||
|
||||
configdir_register_opts(ld, &ld->config_dir, &ld->rpc_filename);
|
||||
config_register_opts(ld);
|
||||
#if DEVELOPER
|
||||
dev_register_opts(ld);
|
||||
|
@ -942,6 +945,11 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[])
|
|||
* later by opt_parse_from_config. */
|
||||
setup_default_config(ld);
|
||||
|
||||
ld->config_dir = default_configdir(ld);
|
||||
opt_register_early_arg("--lightning-dir=<dir>", opt_set_talstr, opt_show_charp,
|
||||
&ld->config_dir,
|
||||
"Set working directory. All other files are relative to this");
|
||||
|
||||
/* Get any configdir/testnet options first. */
|
||||
opt_early_parse_incomplete(argc, argv, opt_log_stderr_exit);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue