mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-25 09:31:00 +00:00
try parsing rpc-host command-line parameter
This commit is contained in:
parent
e9c265e9dc
commit
b568765c75
1 changed files with 10 additions and 1 deletions
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue