From 018abc9dcdf610dc7d88e50a30af526492a19179 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 25 Jan 2016 11:54:15 +0100 Subject: [PATCH] Autogenerate the Args from the docopt macro. --- Cargo.toml | 1 + res/ethereum/tests | 2 +- src/bin/client/main.rs | 29 +++++++++-------------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 82658c6ac..54b1b406e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ evmjit = { path = "rust-evmjit", optional = true } ethash = { path = "ethash" } num_cpus = "0.2" docopt = "0.6" +docopt_macros = "0.6" ctrlc = "1.0" clippy = "0.0.37" diff --git a/res/ethereum/tests b/res/ethereum/tests index e838fd909..dc86e6359 160000 --- a/res/ethereum/tests +++ b/res/ethereum/tests @@ -1 +1 @@ -Subproject commit e838fd90998fc5502d0b7c9427a4c231f9a6953d +Subproject commit dc86e6359675440aea59ddb48648a01c799925d8 diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs index 31bb79d8e..45f45daf7 100644 --- a/src/bin/client/main.rs +++ b/src/bin/client/main.rs @@ -1,7 +1,5 @@ #![feature(plugin)] -// TODO: uncomment once this can be made to work. -//#![plugin(docopt_macros)] - +#![plugin(docopt_macros)] extern crate docopt; extern crate rustc_serialize; extern crate ethcore_util as util; @@ -20,9 +18,8 @@ use ethcore::service::{ClientService, NetSyncMessage}; use ethcore::ethereum; use ethcore::blockchain::CacheSize; use ethcore::sync::EthSync; -use docopt::Docopt; -const USAGE: &'static str = " +docopt!(Args derive Debug, " Parity. Ethereum Client. Usage: @@ -32,15 +29,9 @@ Usage: Options: -l --logging LOGGING Specify the logging level -h --help Show this screen. -"; +"); -#[derive(Debug, RustcDecodable)] -struct Args { - arg_enode: Option>, - flag_logging: Option, -} - -fn setup_log(init: &Option) { +fn setup_log(init: &String) { let mut builder = LogBuilder::new(); builder.filter(None, LogLevelFilter::Info); @@ -48,22 +39,20 @@ fn setup_log(init: &Option) { builder.parse(&env::var("RUST_LOG").unwrap()); } - if let &Some(ref x) = init { - builder.parse(x); - } + builder.parse(init); builder.init().unwrap(); } fn main() { - let args: Args = Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); + let args: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); setup_log(&args.flag_logging); let spec = ethereum::new_frontier(); - let init_nodes = match &args.arg_enode { - &None => spec.nodes().clone(), - &Some(ref enodes) => enodes.clone(), + let init_nodes = match args.arg_enode.len() { + 0 => spec.nodes().clone(), + _ => args.arg_enode.clone(), }; let mut net_settings = NetworkConfiguration::new(); net_settings.boot_nodes = init_nodes;