2016-01-21 21:11:48 +01:00
|
|
|
#include "configdir.h"
|
|
|
|
#include <ccan/opt/opt.h>
|
|
|
|
#include <ccan/tal/path/path.h>
|
|
|
|
#include <ccan/tal/str/str.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2017-12-13 21:00:24 +01:00
|
|
|
/* Override a tal string; frees the old one. */
|
|
|
|
char *opt_set_talstr(const char *arg, char **p)
|
|
|
|
{
|
|
|
|
tal_free(*p);
|
2018-05-03 14:20:26 +02:00
|
|
|
return opt_set_charp(tal_strdup(NULL, arg), p);
|
2017-12-13 21:00:24 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
static char *default_configdir(const tal_t *ctx)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
const char *env = getenv("HOME");
|
|
|
|
if (!env)
|
|
|
|
return ".";
|
|
|
|
|
|
|
|
path = path_join(ctx, env, ".lightning");
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void configdir_register_opts(const tal_t *ctx,
|
|
|
|
char **configdir, char **rpc_filename)
|
|
|
|
{
|
|
|
|
*configdir = default_configdir(ctx);
|
2018-02-02 09:11:09 +01:00
|
|
|
*rpc_filename = tal_strdup(ctx, "lightning-rpc");
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2018-01-25 21:12:57 +01:00
|
|
|
opt_register_early_arg("--lightning-dir=<dir>", opt_set_talstr, opt_show_charp,
|
2016-01-21 21:11:48 +01:00
|
|
|
configdir,
|
2018-01-25 22:21:27 +01:00
|
|
|
"Set working directory. All other files are relative to this");
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2017-12-13 21:00:24 +01:00
|
|
|
opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp,
|
2016-01-21 21:11:48 +01:00
|
|
|
rpc_filename,
|
|
|
|
"Set JSON-RPC socket (or /dev/tty)");
|
|
|
|
}
|