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

Function gateway_list

crates/openshell-cli/src/run.rs:1316–1392  ·  view source on GitHub ↗

List all registered gateways.

(gateway_flag: &Option<String>, output: &str)

Source from the content-addressed store, hash-verified

1314
1315/// List all registered gateways.
1316pub fn gateway_list(gateway_flag: &Option<String>, output: &str) -> Result<()> {
1317 let gateways = list_gateways_with_source()?;
1318 let active = gateway_flag.clone().or_else(load_active_gateway);
1319
1320 if crate::output::print_output_collection(output, &gateways, |g| gateway_to_json(g, &active))? {
1321 return Ok(());
1322 }
1323
1324 if gateways.is_empty() {
1325 println!("No gateways found.");
1326 println!();
1327 println!(
1328 "Register a gateway with: {}",
1329 "openshell gateway add <endpoint>".dimmed()
1330 );
1331 return Ok(());
1332 }
1333
1334 // Calculate column widths
1335 let name_width = gateways
1336 .iter()
1337 .map(|g| g.metadata.name.len())
1338 .max()
1339 .unwrap_or(4)
1340 .max(4);
1341 let endpoint_width = gateways
1342 .iter()
1343 .map(|g| g.metadata.gateway_endpoint.len())
1344 .max()
1345 .unwrap_or(8)
1346 .max(8);
1347 let type_width = gateways
1348 .iter()
1349 .map(|g| gateway_type_label(&g.metadata).len())
1350 .max()
1351 .unwrap_or(4)
1352 .max(4);
1353 let source_width = gateways
1354 .iter()
1355 .map(|g| g.source.label().len())
1356 .max()
1357 .unwrap_or(6)
1358 .max(6);
1359
1360 // Print header
1361 println!(
1362 " {:<name_width$} {:<endpoint_width$} {:<type_width$} {:<source_width$} {}",
1363 "NAME".bold(),
1364 "ENDPOINT".bold(),
1365 "TYPE".bold(),
1366 "SOURCE".bold(),
1367 "AUTH".bold(),
1368 );
1369
1370 // Print rows
1371 for gateway in gateways {
1372 let metadata = &gateway.metadata;
1373 let is_active = active.as_deref() == Some(&metadata.name);

Callers 2

mainFunction · 0.85
gateway_select_withFunction · 0.85

Calls 8

print_output_collectionFunction · 0.85
gateway_to_jsonFunction · 0.85
gateway_type_labelFunction · 0.85
gateway_auth_labelFunction · 0.85
lenMethod · 0.80
is_emptyMethod · 0.45
labelMethod · 0.45

Tested by

no test coverage detected