Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

basic clap cli #186

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ time = "0.1"
evmjit = { path = "rust-evmjit", optional = true }
ethash = { path = "ethash" }
num_cpus = "0.2"
clap = { version = "1.5", features = ["yaml"] }

[features]
jit = ["evmjit"]
Expand Down
14 changes: 14 additions & 0 deletions src/bin/client/cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# NOTE! use 4 spaces instead of tabs.
# rust yml parser do not support tabs

name: parity
version: 0.1.0
about: Ethereum rust implementation

args:
- VERBOSITY:
long: verbosity
help: Logging verbosity (RUST_LOG)
takes_value: true


15 changes: 10 additions & 5 deletions src/bin/client/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#[macro_use]
extern crate clap;

extern crate ethcore_util as util;
extern crate ethcore;
extern crate rustc_serialize;
extern crate log;
extern crate env_logger;

use std::io::stdin;
use std::env;
use log::{LogLevelFilter};
use env_logger::LogBuilder;
use util::*;
Expand All @@ -15,19 +17,22 @@ use ethcore::ethereum;
use ethcore::blockchain::CacheSize;
use ethcore::sync::*;

fn setup_log() {
fn setup_log(filter: Option<&str>) {
let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info);

if env::var("RUST_LOG").is_ok() {
builder.parse(&env::var("RUST_LOG").unwrap());
if let Some(f) = filter {
builder.parse(f);
}

builder.init().unwrap();
}

fn main() {
setup_log();
let yaml = load_yaml!("cli.yml");
let matches = clap::App::from_yaml(yaml).get_matches();
setup_log(matches.value_of("VERBOSITY"));

let spec = ethereum::new_frontier();
let mut service = ClientService::start(spec).unwrap();
let io_handler = Box::new(ClientIoHandler { client: service.client(), timer: 0, info: Default::default() });
Expand Down