cli port option and parsing to config
This commit is contained in:
parent
0f73927e51
commit
5aacf6ea38
|
@ -16,6 +16,7 @@ pub struct Connection<A> where A: io::Read + io::Write {
|
|||
|
||||
pub struct Config {
|
||||
magic: Magic,
|
||||
port: u16,
|
||||
services: ServiceFlags,
|
||||
user_agent: String,
|
||||
start_height: i32,
|
||||
|
|
|
@ -18,4 +18,9 @@ args:
|
|||
value_name: IP
|
||||
help: Connect to a node to retrieve peer addresses, and disconnect
|
||||
takes_value: true
|
||||
- port:
|
||||
long: port
|
||||
value_name: PORT
|
||||
help: Listen for connections on PORT
|
||||
takes_value: true
|
||||
|
||||
|
|
33
pbtc/main.rs
33
pbtc/main.rs
|
@ -16,17 +16,36 @@ use net::common::Magic;
|
|||
fn main() {
|
||||
let yaml = load_yaml!("cli.yml");
|
||||
let matches = clap::App::from_yaml(yaml).get_matches();
|
||||
let _cfg = parse(&matches);
|
||||
}
|
||||
|
||||
let _magic = match matches.is_present("testnet") {
|
||||
struct Config<'a> {
|
||||
magic: Magic,
|
||||
port: u16,
|
||||
connect: Option<&'a str>,
|
||||
seednode: Option<&'a str>,
|
||||
}
|
||||
|
||||
fn parse<'a>(matches: &'a clap::ArgMatches<'a>) -> Result<Config<'a>, String> {
|
||||
let magic = match matches.is_present("testnet") {
|
||||
true => Magic::Testnet,
|
||||
false => Magic::Mainnet,
|
||||
};
|
||||
|
||||
if let Some(ip) = matches.value_of("connect") {
|
||||
println!("Connecting to ip: {}", ip);
|
||||
}
|
||||
let port = match matches.value_of("port") {
|
||||
Some(port) => try!(port.parse().map_err(|_| "Invalid port".to_owned())),
|
||||
None => match magic {
|
||||
Magic::Mainnet => 8333,
|
||||
Magic::Testnet => 18333,
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(ip) = matches.value_of("seednode") {
|
||||
println!("Seednode ip: {}", ip);
|
||||
}
|
||||
let config = Config {
|
||||
magic: magic,
|
||||
port: port,
|
||||
connect: matches.value_of("connect"),
|
||||
seednode: matches.value_of("seednode"),
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue