Merge pull request #205 from ethcore/cleanerclioptions
Autogenerate the Args from the docopt macro.
This commit is contained in:
commit
d649f1aca9
@ -21,6 +21,7 @@ evmjit = { path = "rust-evmjit", optional = true }
|
|||||||
ethash = { path = "ethash" }
|
ethash = { path = "ethash" }
|
||||||
num_cpus = "0.2"
|
num_cpus = "0.2"
|
||||||
docopt = "0.6"
|
docopt = "0.6"
|
||||||
|
docopt_macros = "0.6"
|
||||||
ctrlc = "1.0"
|
ctrlc = "1.0"
|
||||||
clippy = "0.0.37"
|
clippy = "0.0.37"
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit e838fd90998fc5502d0b7c9427a4c231f9a6953d
|
Subproject commit dc86e6359675440aea59ddb48648a01c799925d8
|
@ -1,7 +1,5 @@
|
|||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
// TODO: uncomment once this can be made to work.
|
#![plugin(docopt_macros)]
|
||||||
//#![plugin(docopt_macros)]
|
|
||||||
|
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
@ -20,9 +18,8 @@ use ethcore::service::{ClientService, NetSyncMessage};
|
|||||||
use ethcore::ethereum;
|
use ethcore::ethereum;
|
||||||
use ethcore::blockchain::CacheSize;
|
use ethcore::blockchain::CacheSize;
|
||||||
use ethcore::sync::EthSync;
|
use ethcore::sync::EthSync;
|
||||||
use docopt::Docopt;
|
|
||||||
|
|
||||||
const USAGE: &'static str = "
|
docopt!(Args derive Debug, "
|
||||||
Parity. Ethereum Client.
|
Parity. Ethereum Client.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@ -32,15 +29,9 @@ Usage:
|
|||||||
Options:
|
Options:
|
||||||
-l --logging LOGGING Specify the logging level
|
-l --logging LOGGING Specify the logging level
|
||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
";
|
");
|
||||||
|
|
||||||
#[derive(Debug, RustcDecodable)]
|
fn setup_log(init: &String) {
|
||||||
struct Args {
|
|
||||||
arg_enode: Option<Vec<String>>,
|
|
||||||
flag_logging: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_log(init: &Option<String>) {
|
|
||||||
let mut builder = LogBuilder::new();
|
let mut builder = LogBuilder::new();
|
||||||
builder.filter(None, LogLevelFilter::Info);
|
builder.filter(None, LogLevelFilter::Info);
|
||||||
|
|
||||||
@ -48,22 +39,20 @@ fn setup_log(init: &Option<String>) {
|
|||||||
builder.parse(&env::var("RUST_LOG").unwrap());
|
builder.parse(&env::var("RUST_LOG").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let &Some(ref x) = init {
|
builder.parse(init);
|
||||||
builder.parse(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.init().unwrap();
|
builder.init().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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);
|
setup_log(&args.flag_logging);
|
||||||
|
|
||||||
let spec = ethereum::new_frontier();
|
let spec = ethereum::new_frontier();
|
||||||
let init_nodes = match &args.arg_enode {
|
let init_nodes = match args.arg_enode.len() {
|
||||||
&None => spec.nodes().clone(),
|
0 => spec.nodes().clone(),
|
||||||
&Some(ref enodes) => enodes.clone(),
|
_ => args.arg_enode.clone(),
|
||||||
};
|
};
|
||||||
let mut net_settings = NetworkConfiguration::new();
|
let mut net_settings = NetworkConfiguration::new();
|
||||||
net_settings.boot_nodes = init_nodes;
|
net_settings.boot_nodes = init_nodes;
|
||||||
|
Loading…
Reference in New Issue
Block a user