From 71ea7bddfc5063f9346308eec9d37429f8506dd0 Mon Sep 17 00:00:00 2001 From: Orbital Date: Fri, 26 Jan 2024 16:31:46 -0600 Subject: [PATCH] cli: add global arguments for connecting to lnd --- Cargo.toml | 2 +- src/cli.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a991cf25..290385ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ spec = "config_spec.toml" [dependencies] async-trait = "0.1.66" bitcoin = { version = "0.30.2", features = ["rand"] } -clap = { version = "4.4.6", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive", "string"] } futures = "0.3.26" home = "0.5.5" lightning = { version = "0.0.120", features = ["max_level_trace"] } diff --git a/src/cli.rs b/src/cli.rs index 42d6c9f9..7ca725cb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,11 +1,54 @@ use clap::{Parser, Subcommand}; use lndk::lndk_offers::decode; +use std::ffi::OsString; + +fn get_cert_path_default() -> OsString { + home::home_dir() + .unwrap() + .as_path() + .join(".lnd") + .join("tls.cert") + .into_os_string() +} + +fn get_macaroon_path_default() -> OsString { + home::home_dir() + .unwrap() + .as_path() + .join(".lnd/data/chain/bitcoin/regtest/admin.macaroon") + .into_os_string() +} /// A cli for interacting with lndk. #[derive(Debug, Parser)] #[command(name = "lndk-cli")] #[command(about = "A cli for interacting with lndk", long_about = None)] struct Cli { + /// Global variables + #[arg( + short, + long, + global = true, + required = false, + default_value = "regtest" + )] + network: String, + + #[arg(short, long, global = true, required = false, default_value = get_cert_path_default())] + tls_cert: String, + + #[arg(short, long, global = true, required = false, default_value = get_macaroon_path_default())] + macaroon: String, + + #[arg( + short, + long, + global = true, + required = false, + default_value = "https://localhost:10009" + )] + address: String, + #[command(subcommand)] command: Commands, }