use std::path::PathBuf;
use clap::{Parser, ValueHint};
use internet2::addr::ServiceAddr;
use lnpbp::chain::Chain;
use microservices::shell::shell_setup;
use store_rpc::STORED_RPC_ENDPOINT;
#[cfg(any(target_os = "linux"))]
pub const BP_NODE_DATA_DIR: &str = "~/.bp";
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
pub const BP_NODE_DATA_DIR: &str = "~/.bp";
#[cfg(target_os = "macos")]
pub const BP_NODE_DATA_DIR: &str = "~/Library/Application Support/BP Node";
#[cfg(target_os = "windows")]
pub const BP_NODE_DATA_DIR: &str = "~\\AppData\\Local\\BP Node";
#[cfg(target_os = "ios")]
pub const BP_NODE_DATA_DIR: &str = "~/Documents";
#[cfg(target_os = "android")]
pub const BP_NODE_DATA_DIR: &str = ".";
pub const RGB_NODE_CTL_ENDPOINT: &str = "{data_dir}/ctl";
pub const BP_NODE_CONFIG: &str = "{data_dir}/bp_node.toml";
#[derive(Parser)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct Opts {
#[clap(short, long, global = true, parse(from_occurrences))]
pub verbose: u8,
#[clap(
short,
long,
global = true,
default_value = BP_NODE_DATA_DIR,
env = "BP_NODE_DATA_DIR",
value_hint = ValueHint::DirPath
)]
pub data_dir: PathBuf,
#[clap(
short = 'S',
long = "store",
global = true,
env = "STORED_RPC_ENDPOINT",
default_value = STORED_RPC_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub store_endpoint: ServiceAddr,
#[clap(
short = 'X',
long = "ctl",
global = true,
env = "RGB_NODE_CTL_ENDPOINT",
default_value = RGB_NODE_CTL_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub ctl_endpoint: ServiceAddr,
#[clap(
short = 'n',
long,
global = true,
alias = "network",
default_value = "signet",
env = "BP_NODE_NETWORK"
)]
pub chain: Chain,
#[clap(
long,
global = true,
default_value("pandora.network"),
env = "BP_NODE_ELECTRUM_SERVER",
value_hint = ValueHint::Hostname
)]
pub electrum_server: String,
#[clap(long, global = true, env = "BP_NODE_ELECTRUM_PORT")]
pub electrum_port: Option<u16>,
}
impl Opts {
pub fn process(&mut self) {
shell_setup(
self.verbose,
[&mut self.ctl_endpoint, &mut self.store_endpoint],
&mut self.data_dir,
&[("{chain}", self.chain.to_string())],
);
}
}