feat: improve cli (#16)
* use default_value for flags * add checkpoint flag
This commit is contained in:
parent
a149ba618c
commit
b8d21abe44
|
@ -1936,6 +1936,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"client",
|
||||
"common",
|
||||
"config",
|
||||
"dirs",
|
||||
"env_logger",
|
||||
|
|
|
@ -13,4 +13,4 @@ log = "0.4.17"
|
|||
|
||||
client = { path = "../client" }
|
||||
config = { path = "../config" }
|
||||
|
||||
common = { path = "../common" }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use clap::Parser;
|
||||
use common::utils::hex_str_to_bytes;
|
||||
use dirs::home_dir;
|
||||
use env_logger::Env;
|
||||
use eyre::Result;
|
||||
|
@ -14,7 +15,7 @@ async fn main() -> Result<()> {
|
|||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
||||
let cli = Cli::parse();
|
||||
let config = match cli.network.as_str() {
|
||||
let mut config = match cli.network.as_str() {
|
||||
"goerli" => networks::goerli(),
|
||||
_ => {
|
||||
let home = home_dir().unwrap();
|
||||
|
@ -23,12 +24,16 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
if let Some(checkpoint) = cli.checkpoint {
|
||||
config.general.checkpoint = hex_str_to_bytes(&checkpoint)?;
|
||||
}
|
||||
|
||||
let mut client = Client::new(Arc::new(config)).await?;
|
||||
client.sync().await?;
|
||||
|
||||
let client = Arc::new(Mutex::new(client));
|
||||
|
||||
let mut rpc = Rpc::new(client.clone(), cli.port.unwrap_or(8545));
|
||||
let mut rpc = Rpc::new(client.clone(), cli.port);
|
||||
rpc.start().await?;
|
||||
|
||||
loop {
|
||||
|
@ -39,8 +44,10 @@ async fn main() -> Result<()> {
|
|||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[clap(long)]
|
||||
#[clap(short, long, default_value = "goerli")]
|
||||
network: String,
|
||||
#[clap(long)]
|
||||
port: Option<u16>,
|
||||
#[clap(short, long, default_value = "8545")]
|
||||
port: u16,
|
||||
#[clap(short, long)]
|
||||
checkpoint: Option<String>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue