From b568765c75324c71df633d0cf1d1b157661c16a9 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Tue, 1 Jun 2021 19:05:15 +0200 Subject: try parsing rpc-host command-line parameter --- src/garage/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/garage/main.rs b/src/garage/main.rs index a78e0f03..66828cba 100644 --- a/src/garage/main.rs +++ b/src/garage/main.rs @@ -28,7 +28,7 @@ use cli::*; #[structopt(name = "garage")] struct Opt { /// RPC connect to this host to execute client operations - #[structopt(short = "h", long = "rpc-host", default_value = "127.0.0.1:3901")] + #[structopt(short = "h", long = "rpc-host", default_value = "127.0.0.1:3901", parse(try_from_str = parse_address))] pub rpc_host: SocketAddr, #[structopt(long = "ca-cert")] @@ -87,3 +87,12 @@ async fn cli_command(opt: Opt) -> Result<(), Error> { cli_cmd(opt.cmd, membership_rpc_cli, admin_rpc_cli, opt.rpc_host).await } + +fn parse_address(address: &str) -> Result { + use std::net::ToSocketAddrs; + address + .to_socket_addrs() + .map_err(|_| format!("Could not resolve {}", address))? + .next() + .ok_or_else(|| format!("Could not resolve {}", address)) +} -- cgit v1.2.3