aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/garage/main.rs11
1 files changed, 10 insertions, 1 deletions
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<SocketAddr, String> {
+ use std::net::ToSocketAddrs;
+ address
+ .to_socket_addrs()
+ .map_err(|_| format!("Could not resolve {}", address))?
+ .next()
+ .ok_or_else(|| format!("Could not resolve {}", address))
+}