aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-06-01 19:05:15 +0200
committerGitea <gitea@fake.local>2021-06-01 23:53:58 +0200
commitb568765c75324c71df633d0cf1d1b157661c16a9 (patch)
treeac6c3944a3d6ec94db376a31606df735a613fc9c
parente9c265e9dc6979095251e7d938c46206c98a5473 (diff)
downloadgarage-b568765c75324c71df633d0cf1d1b157661c16a9.tar.gz
garage-b568765c75324c71df633d0cf1d1b157661c16a9.zip
try parsing rpc-host command-line parameter
-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))
+}