MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / print_service_endpoint_table

Function print_service_endpoint_table

crates/openshell-cli/src/run.rs:4277–4329  ·  view source on GitHub ↗
(services: &[ServiceEndpointResponse], gateway_endpoint: &str)

Source from the content-addressed store, hash-verified

4275}
4276
4277fn print_service_endpoint_table(services: &[ServiceEndpointResponse], gateway_endpoint: &str) {
4278 let rows = services
4279 .iter()
4280 .filter_map(|response| {
4281 let endpoint = response.endpoint.as_ref()?;
4282 let service = service_display_name(&endpoint.service_name).to_string();
4283 let target = format!("127.0.0.1:{}", endpoint.target_port);
4284 let url = if response.url.is_empty() {
4285 String::new()
4286 } else {
4287 service_url_for_gateway(&response.url, gateway_endpoint)
4288 };
4289 Some((endpoint.sandbox_name.clone(), service, target, url))
4290 })
4291 .collect::<Vec<_>>();
4292
4293 if rows.is_empty() {
4294 return;
4295 }
4296
4297 let sandbox_width = rows
4298 .iter()
4299 .map(|(sandbox, _, _, _)| sandbox.len())
4300 .max()
4301 .unwrap_or(7)
4302 .max(7);
4303 let service_width = rows
4304 .iter()
4305 .map(|(_, service, _, _)| service.len())
4306 .max()
4307 .unwrap_or(7)
4308 .max(7);
4309 let target_width = rows
4310 .iter()
4311 .map(|(_, _, target, _)| target.len())
4312 .max()
4313 .unwrap_or(6)
4314 .max(6);
4315
4316 println!(
4317 "{:<sandbox_width$} {:<service_width$} {:<target_width$} {}",
4318 "SANDBOX".bold(),
4319 "SERVICE".bold(),
4320 "TARGET".bold(),
4321 "URL".bold(),
4322 );
4323
4324 for (sandbox, service, target, url) in rows {
4325 println!(
4326 "{sandbox:<sandbox_width$} {service:<service_width$} {target:<target_width$} {url}"
4327 );
4328 }
4329}
4330
4331fn service_display_name(service: &str) -> &str {
4332 if service.is_empty() { "-" } else { service }

Callers 2

service_listFunction · 0.85
service_getFunction · 0.85

Calls 4

service_url_for_gatewayFunction · 0.85
lenMethod · 0.80
service_display_nameFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected