1use clap::{Parser, Subcommand};
4use tracing_subscriber::layer::SubscriberExt;
5
6use crate::{
7 faucet::FaucetArgs,
8 identity::IdentitySubcommands,
9 network_registry::NetworkRegistrySubcommands,
10 safe_module::SafeModuleSubcommands,
11 utils::{Cmd, HelperErrors},
12 win_prob::WinProbSubcommands,
13};
14pub mod environment_config;
15pub mod faucet;
16pub mod identity;
17pub mod key_pair;
18pub mod methods;
19pub mod network_registry;
20pub mod safe_module;
21pub mod utils;
22pub mod win_prob;
23
24#[global_allocator]
27static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
28
29#[derive(Parser, Debug)]
30#[command(author, version, about, long_about = None)]
31struct Cli {
32 #[command(subcommand)]
33 pub command: Commands,
34}
35
36#[derive(Subcommand, Debug)]
38enum Commands {
39 #[command(visible_alias = "id")]
41 Identity {
42 #[command(subcommand)]
43 command: IdentitySubcommands,
44 },
45
46 #[clap(about = "Fund given address and/or addressed derived from identity files native tokens or HOPR tokens")]
48 Faucet(FaucetArgs),
49
50 #[command(visible_alias = "nr")]
52 NetworkRegistry {
53 #[command(subcommand)]
54 command: NetworkRegistrySubcommands,
55 },
56
57 #[command(visible_alias = "sm")]
59 SafeModule {
60 #[command(subcommand)]
61 command: SafeModuleSubcommands,
62 },
63
64 #[command(visible_alias = "wp")]
66 WinProb {
67 #[command(subcommand)]
68 command: WinProbSubcommands,
69 },
70}
71
72#[tokio::main]
73async fn main() -> Result<(), HelperErrors> {
74 let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
75 .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
76 let format = tracing_subscriber::fmt::layer()
77 .with_level(true)
78 .with_target(true)
79 .with_thread_ids(true)
80 .with_thread_names(false);
81
82 let subscriber = tracing_subscriber::Registry::default().with(env_filter).with(format);
83
84 tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber");
85
86 let cli = Cli::parse();
87
88 match cli.command {
89 Commands::Identity { command } => {
90 command.run()?;
91 }
92 Commands::Faucet(opt) => {
93 opt.async_run().await?;
94 }
95 Commands::NetworkRegistry { command } => {
96 command.async_run().await?;
97 }
98 Commands::SafeModule { command } => {
99 command.async_run().await?;
100 }
101 Commands::WinProb { command } => {
102 command.async_run().await?;
103 }
104 }
105
106 Ok(())
107}