Add get-rpc-url --all flag (#6533)

This commit is contained in:
Michael Vines 2019-10-24 10:44:05 -07:00 committed by GitHub
parent a2543e5a8d
commit 8e5e48dd92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -45,6 +45,12 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.subcommand(
SubCommand::with_name("get-rpc-url")
.about("Get an RPC URL for the cluster")
.arg(
Arg::with_name("all")
.long("all")
.takes_value(false)
.help("Return all RPC URLs"),
)
.arg(
Arg::with_name("timeout")
.long("timeout")
@ -194,18 +200,23 @@ fn main() -> Result<(), Box<dyn error::Error>> {
gossip_addr.as_ref(),
)?;
let rpc_addr = nodes
let rpc_addrs: Vec<_> = nodes
.iter()
.filter_map(ContactInfo::valid_client_facing_addr)
.map(|addrs| addrs.0)
.find(|rpc_addr| rpc_addr.ip() == entrypoint_addr.ip());
.filter(|rpc_addr| {
matches.is_present("all") || rpc_addr.ip() == entrypoint_addr.ip()
})
.collect();
if rpc_addr.is_none() {
if rpc_addrs.is_empty() {
eprintln!("No RPC URL found");
exit(1);
}
println!("http://{}", rpc_addr.unwrap());
for rpc_addr in rpc_addrs {
println!("http://{}", rpc_addr);
}
}
("stop", Some(matches)) => {
let pubkey = matches