stored/
opts.rs

1// Storage daemon (stored): microservice frontend for different storage backends
2// used in LNP/BP nodes.
3//
4// Written in 2022 by
5//     Dr. Maxim Orlovsky <orlovsky@lnp-bp.org>
6//
7// Copyright (C) 2022 by LNP/BP Standards Association, Switzerland.
8//
9// You should have received a copy of the MIT License along with this software.
10// If not, see <https://opensource.org/licenses/MIT>.
11
12use std::path::PathBuf;
13
14use clap::{Parser, ValueHint};
15use internet2::addr::ServiceAddr;
16use microservices::shell::shell_setup;
17use store_rpc::STORED_RPC_ENDPOINT;
18
19#[cfg(any(target_os = "linux"))]
20pub const STORED_DATA_DIR: &str = "~/.storm_node";
21#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
22pub const STORED_DATA_DIR: &str = "~/.storm_node";
23#[cfg(target_os = "macos")]
24pub const STORED_DATA_DIR: &str = "~/Library/Application Support/Storm Node";
25#[cfg(target_os = "windows")]
26pub const STORED_DATA_DIR: &str = "~\\AppData\\Local\\Storm Node";
27#[cfg(target_os = "ios")]
28pub const STORED_DATA_DIR: &str = "~/Documents";
29#[cfg(target_os = "android")]
30pub const STORED_DATA_DIR: &str = ".";
31
32pub const STORED_CONFIG: &str = "{data_dir}/stored.toml";
33
34/// Command-line arguments
35#[derive(Parser)]
36#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
37#[clap(author, version, name = "stored", about = "stored: storage microservice daemon")]
38pub struct Opts {
39    /// Set verbosity level.
40    ///
41    /// Can be used multiple times to increase verbosity
42    #[clap(short, long, global = true, parse(from_occurrences))]
43    pub verbose: u8,
44
45    /// Data directory path.
46    ///
47    /// Path to the directory that contains stored data, and where ZMQ RPC
48    /// socket files are located
49    #[clap(
50        short,
51        long,
52        global = true,
53        default_value = STORED_DATA_DIR,
54        env = "STORED_DATA_DIR",
55        value_hint = ValueHint::DirPath
56    )]
57    pub data_dir: PathBuf,
58
59    /// ZMQ socket name/address for Storm Node client-server RPC API.
60    ///
61    /// Socket can be either TCP address in form of `<ipv4 | ipv6>:<port>` – or a path
62    /// to an IPC file.
63    #[clap(
64        short = 'X',
65        long = "rpc",
66        global = true,
67        env = "STORED_RPC_ENDPOINT",
68        value_hint = ValueHint::FilePath,
69        default_value = STORED_RPC_ENDPOINT
70    )]
71    pub rpc_endpoint: ServiceAddr,
72
73    /// Database table names to use.
74    #[clap()]
75    pub tables: Vec<String>,
76}
77
78impl Opts {
79    pub fn process(&mut self) {
80        shell_setup(self.verbose, [&mut self.rpc_endpoint], &mut self.data_dir, &[]);
81    }
82}