vls_proxy/util/
mod.rs

1mod env_var;
2
3pub use env_var::*;
4
5#[cfg(feature = "main")]
6use clap::{Arg, ArgAction, ArgMatches, Command};
7use tokio::runtime::{self, Runtime};
8
9#[cfg(feature = "main")]
10pub fn add_hsmd_args(app: Command) -> Command {
11    app.version("1.0.0")
12        .disable_version_flag(true)
13        .arg(
14            Arg::new("dev-disconnect")
15                .action(ArgAction::SetTrue)
16                .help("ignored dev flag")
17                .long("dev-disconnect"),
18        )
19        .arg(
20            Arg::new("developer")
21                .long("developer")
22                .action(ArgAction::SetTrue)
23                .help("ignored dev flag"),
24        )
25        .arg(
26            Arg::new("log-io").long("log-io").action(ArgAction::SetTrue).help(
27                "ignored flag to set log level as we rely on `RUST_LOG` environment variable",
28            ),
29        )
30        .arg(
31            Arg::new("log-trace").long("log-trace").action(ArgAction::SetTrue).help(
32                "ignored flag to set log level as we rely on `RUST_LOG` environment variable",
33            ),
34        )
35        .arg(
36            Arg::new("version")
37                .long("version")
38                .action(ArgAction::SetTrue)
39                .help("show a dummy version"),
40        )
41        .arg(
42            Arg::new("git-desc")
43                .long("git-desc")
44                .help("print git desc version and exit")
45                .action(ArgAction::SetTrue),
46        )
47        .arg(
48            Arg::new("datadir")
49                .long("datadir")
50                .help("data directory")
51                .action(ArgAction::Set)
52                .default_value(".")
53                .value_name("DIR"),
54        )
55}
56
57#[cfg(feature = "main")]
58pub fn handle_hsmd_version(matches: &ArgMatches) -> bool {
59    if matches.get_flag("version") {
60        // Pretend to be the right version, given to us by an env var
61        let version = vls_cln_version();
62        println!("{}", version);
63        true
64    } else {
65        false
66    }
67}
68
69pub fn create_runtime(thread_name: &str) -> Runtime {
70    let thrname = thread_name.to_string();
71    std::thread::spawn(|| {
72        runtime::Builder::new_multi_thread()
73            .enable_all()
74            .thread_name(thrname)
75            .worker_threads(2) // for debugging
76            .build()
77    })
78    .join()
79    .expect("runtime join")
80    .expect("runtime")
81}