1use crate::error::Result;
2use clap::{Parser, Subcommand};
3use gl_client::bitcoin::Network;
4use std::{path::PathBuf, str::FromStr};
5mod error;
6pub mod model;
7mod node;
8mod scheduler;
9mod signer;
10mod util;
11
12#[derive(Parser, Debug)]
13#[command(author, version, about, long_about = None)]
14pub struct Cli {
15 #[arg(short, long, global = true, help_heading = "Global options")]
17 data_dir: Option<String>,
18 #[arg(short, long, default_value = "bitcoin", value_parser = clap::value_parser!(Network), global = true, help_heading = "Global options")]
20 network: Network,
21 #[arg(long, short, global = true, help_heading = "Global options")]
22 verbose: bool,
23 #[command(subcommand)]
24 cmd: Commands,
25}
26
27#[derive(Subcommand, Debug)]
28pub enum Commands {
29 #[command(subcommand)]
31 Scheduler(scheduler::Command),
32 #[command(subcommand)]
34 Signer(signer::Command),
35 #[command(subcommand)]
37 Node(node::Command),
38}
39
40pub async fn run(cli: Cli) -> Result<()> {
41 if cli.verbose {
42 if std::env::var("RUST_LOG").is_err() {
43 std::env::set_var("RUST_LOG", "debug")
44 }
45 env_logger::init();
46 }
47
48 let data_dir = cli
49 .data_dir
50 .map(|d| util::DataDir(PathBuf::from_str(&d).expect("is not a valid path")))
51 .unwrap_or_default();
52
53 Ok(match cli.cmd {
54 Commands::Scheduler(cmd) => {
55 scheduler::command_handler(
56 cmd,
57 scheduler::Config {
58 data_dir,
59 network: cli.network,
60 },
61 )
62 .await?
63 }
64
65 Commands::Signer(cmd) => {
66 signer::command_handler(
67 cmd,
68 signer::Config {
69 data_dir,
70 network: cli.network,
71 },
72 )
73 .await?
74 }
75 Commands::Node(cmd) => {
76 node::command_handler(
77 cmd,
78 node::Config {
79 data_dir,
80 network: cli.network,
81 },
82 )
83 .await?
84 }
85 })
86}