use std::fmt::Debug;
use std::path::PathBuf;
use clap::{Parser, ValueHint};
use internet2::addr::ServiceAddr;
use store_rpc::STORED_RPC_ENDPOINT;
use storm_ext::{STORM_NODE_DATA_DIR, STORM_NODE_EXT_ENDPOINT};
use storm_rpc::{CHATD_RPC_ENDPOINT, STORM_NODE_RPC_ENDPOINT};
pub const STORM_NODE_CTL_ENDPOINT: &str = "{data_dir}/ctl";
pub const STORM_NODE_CONFIG: &str = "{data_dir}/stormd.toml";
pub trait Options: Clone + Eq + Debug {
type Conf;
fn shared(&self) -> &Opts;
fn config(&self) -> Self::Conf;
}
#[derive(Parser)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[clap(author, version, name = "stormd", about = "storm node managing service")]
pub struct Opts {
#[clap(short, long, global = true, parse(from_occurrences))]
pub verbose: u8,
#[clap(
short,
long,
global = true,
default_value = STORM_NODE_DATA_DIR,
env = "STORM_NODE_DATA_DIR",
value_hint = ValueHint::DirPath
)]
pub data_dir: PathBuf,
#[clap(
short,
long,
global = true,
env = "STORM_NODE_CONFIG",
value_hint = ValueHint::FilePath
)]
pub config: Option<PathBuf>,
#[clap(
short = 'M',
long = "msg",
env = "LNP_NODE_MSG_ENDPOINT",
value_hint = ValueHint::FilePath
)]
pub msg_endpoint: ServiceAddr,
#[clap(
short = 'X',
long = "ctl",
global = true,
env = "STORM_NODE_CTL_ENDPOINT",
default_value = STORM_NODE_CTL_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub ctl_endpoint: ServiceAddr,
#[clap(
short = 'R',
long,
env = "STORM_NODE_RPC_ENDPOINT",
value_hint = ValueHint::FilePath,
default_value = STORM_NODE_RPC_ENDPOINT
)]
pub rpc_endpoint: ServiceAddr,
#[clap(
short = 'E',
long,
env = "STORM_NODE_EXT_ENDPOINT",
value_hint = ValueHint::FilePath,
default_value = STORM_NODE_EXT_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub ext_endpoint: ServiceAddr,
#[clap(
short = 'S',
long,
global = true,
env = "STORED_RPC_ENDPOINT",
default_value = STORED_RPC_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub store_endpoint: ServiceAddr,
#[clap(
short = 'C',
long,
global = true,
env = "CHATD_RPC_ENDPOINT",
default_value = CHATD_RPC_ENDPOINT,
)]
pub chat_endpoint: ServiceAddr,
}
#[cfg(feature = "server")]
impl Opts {
pub fn process(&mut self) {
microservices::shell::shell_setup(
self.verbose,
[
&mut self.msg_endpoint,
&mut self.ctl_endpoint,
&mut self.rpc_endpoint,
&mut self.ext_endpoint,
&mut self.chat_endpoint,
],
&mut self.data_dir,
&[],
);
}
}