feat: improve cli (#16)

* use default_value for flags

* add checkpoint flag
This commit is contained in:
Noah Citron 2022-09-09 18:14:17 -04:00 committed by GitHub
parent a149ba618c
commit b8d21abe44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

1
Cargo.lock generated
View File

@ -1936,6 +1936,7 @@ version = "0.1.0"
dependencies = [
"clap",
"client",
"common",
"config",
"dirs",
"env_logger",

View File

@ -13,4 +13,4 @@ log = "0.4.17"
client = { path = "../client" }
config = { path = "../config" }
common = { path = "../common" }

View File

@ -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>,
}