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 = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"client",
|
"client",
|
||||||
|
"common",
|
||||||
"config",
|
"config",
|
||||||
"dirs",
|
"dirs",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
|
@ -13,4 +13,4 @@ log = "0.4.17"
|
||||||
|
|
||||||
client = { path = "../client" }
|
client = { path = "../client" }
|
||||||
config = { path = "../config" }
|
config = { path = "../config" }
|
||||||
|
common = { path = "../common" }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use common::utils::hex_str_to_bytes;
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
@ -14,7 +15,7 @@ async fn main() -> Result<()> {
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let config = match cli.network.as_str() {
|
let mut config = match cli.network.as_str() {
|
||||||
"goerli" => networks::goerli(),
|
"goerli" => networks::goerli(),
|
||||||
_ => {
|
_ => {
|
||||||
let home = home_dir().unwrap();
|
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?;
|
let mut client = Client::new(Arc::new(config)).await?;
|
||||||
client.sync().await?;
|
client.sync().await?;
|
||||||
|
|
||||||
let client = Arc::new(Mutex::new(client));
|
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?;
|
rpc.start().await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -39,8 +44,10 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(long)]
|
#[clap(short, long, default_value = "goerli")]
|
||||||
network: String,
|
network: String,
|
||||||
#[clap(long)]
|
#[clap(short, long, default_value = "8545")]
|
||||||
port: Option<u16>,
|
port: u16,
|
||||||
|
#[clap(short, long)]
|
||||||
|
checkpoint: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue