initial node parameters
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jake Hillion 2021-06-16 21:59:12 +01:00
parent 63a746521c
commit b7d9d19c4c

View File

@ -1,7 +1,14 @@
use std::path::PathBuf;
use std::net::SocketAddr;
use std::net::ToSocketAddrs;
use std::io;
use structopt::StructOpt;
pub const DEFAULT_PORT: u16 = 8443;
const DEFAULT_PORT_STR: &str = "8443";
#[derive(Debug, StructOpt)]
enum Node {
/// Run the node
@ -14,16 +21,31 @@ enum Node {
#[structopt(short = "d", long = "daemon")]
daemon: bool,
#[structopt(short = "p", long = "port", default_value = "8443")]
/// Port on which to run the node
#[structopt(short = "p", long = "port", default_value = DEFAULT_PORT_STR)]
port: u16,
/// Path in which to store node content
#[structopt(long = "path", default_value = ".unnamed/node")]
path: PathBuf,
/// Nodes to initially connect to
#[structopt(long = "initial_nodes", parse(try_from_str = parse_connection_address))]
initial_nodes: Vec<SocketAddr>,
},
}
fn parse_connection_address(arg: &str) -> io::Result<SocketAddr> {
let mut addrs = arg.to_socket_addrs().or_else(|_| (arg, DEFAULT_PORT).to_socket_addrs())?;
Ok(addrs.next().expect("no socket addr"))
}
fn main() {
let node = Node::from_args();
println!("{:?}", node);
}
fn run() -> Result<(), ()> {
Ok(())
}