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#[derive(Parser, Debug)]
25#[command(author, version, about, long_about = None)]
26struct Cli {
27 #[command(subcommand)]
28 pub command: Commands,
29}
30
31#[derive(Subcommand, Debug)]
33enum Commands {
34 #[command(visible_alias = "id")]
36 Identity {
37 #[command(subcommand)]
38 command: IdentitySubcommands,
39 },
40
41 #[clap(about = "Fund given address and/or addressed derived from identity files native tokens or HOPR tokens")]
43 Faucet(FaucetArgs),
44
45 #[command(visible_alias = "nr")]
47 NetworkRegistry {
48 #[command(subcommand)]
49 command: NetworkRegistrySubcommands,
50 },
51
52 #[command(visible_alias = "sm")]
54 SafeModule {
55 #[command(subcommand)]
56 command: SafeModuleSubcommands,
57 },
58
59 #[command(visible_alias = "wp")]
61 WinProb {
62 #[command(subcommand)]
63 command: WinProbSubcommands,
64 },
65}
66
67#[tokio::main]
68async fn main() -> Result<(), HelperErrors> {
69 let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
70 .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
71 let format = tracing_subscriber::fmt::layer()
72 .with_level(true)
73 .with_target(true)
74 .with_thread_ids(true)
75 .with_thread_names(false);
76
77 let subscriber = tracing_subscriber::Registry::default().with(env_filter).with(format);
78
79 tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber");
80
81 let cli = Cli::parse();
82
83 match cli.command {
84 Commands::Identity { command } => {
85 command.run()?;
86 }
87 Commands::Faucet(opt) => {
88 opt.async_run().await?;
89 }
90 Commands::NetworkRegistry { command } => {
91 command.async_run().await?;
92 }
93 Commands::SafeModule { command } => {
94 command.async_run().await?;
95 }
96 Commands::WinProb { command } => {
97 command.async_run().await?;
98 }
99 }
100
101 Ok(())
102}