parity-zcash/pbtc/config.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

use std::net;
2016-10-02 18:01:46 -07:00
use clap;
2016-10-03 07:29:07 -07:00
use message::common::Magic;
2016-10-02 18:01:46 -07:00
pub struct Config {
2016-10-02 18:01:46 -07:00
pub magic: Magic,
pub port: u16,
pub connect: Option<net::IpAddr>,
pub seednode: Option<String>,
pub print_to_console: bool,
pub use_disk_database: bool,
2016-10-30 19:12:44 -07:00
pub import_path: Option<String>,
2016-10-02 18:01:46 -07:00
}
pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
let print_to_console = matches.is_present("printtoconsole");
let use_disk_database = matches.is_present("diskdb");
2016-10-02 18:01:46 -07:00
let magic = match matches.is_present("testnet") {
true => Magic::Testnet,
false => Magic::Mainnet,
};
let port = match matches.value_of("port") {
Some(port) => try!(port.parse().map_err(|_| "Invalid port".to_owned())),
None => magic.port(),
};
let connect = match matches.value_of("connect") {
Some(s) => Some(try!(s.parse().map_err(|_| "Invalid connect".to_owned()))),
None => None,
};
let seednode = match matches.value_of("seednode") {
Some(s) => Some(try!(s.parse().map_err(|_| "Invalid seednode".to_owned()))),
None => None,
2016-10-02 18:01:46 -07:00
};
2016-10-30 19:12:44 -07:00
let import_path = match matches.value_of("import") {
Some(s) => Some(try!(s.parse().map_err(|_| "Invalid import path".to_owned()))),
None => None,
};
2016-10-02 18:01:46 -07:00
let config = Config {
print_to_console: print_to_console,
2016-10-02 18:01:46 -07:00
magic: magic,
port: port,
connect: connect,
seednode: seednode,
use_disk_database: use_disk_database,
2016-10-30 19:12:44 -07:00
import_path: import_path,
2016-10-02 18:01:46 -07:00
};
Ok(config)
}