This commit is contained in:
parent
63a746521c
commit
b7d9d19c4c
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user