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

Function parse_tcp_forward_spec

crates/openshell-cli/src/run.rs:3014–3034  ·  view source on GitHub ↗
(local: Option<&str>, default_port: u16)

Source from the content-addressed store, hash-verified

3012impl std::error::Error for ForwardTcpConnectionError {}
3013
3014fn parse_tcp_forward_spec(local: Option<&str>, default_port: u16) -> Result<(String, u16)> {
3015 let Some(spec) = local else {
3016 return Ok(("127.0.0.1".to_string(), default_port));
3017 };
3018
3019 if let Some(pos) = spec.rfind(':') {
3020 let addr = &spec[..pos];
3021 let port_str = &spec[pos + 1..];
3022 if let Ok(port) = port_str.parse::<u16>() {
3023 if addr.is_empty() {
3024 return Err(miette::miette!("bind address is required before ':'"));
3025 }
3026 return Ok((addr.to_string(), port));
3027 }
3028 }
3029
3030 let port: u16 = spec.parse().map_err(|_| {
3031 miette::miette!("invalid local forward spec '{spec}': expected [bind_address:]port")
3032 })?;
3033 Ok(("127.0.0.1".to_string(), port))
3034}
3035
3036async fn forward_one_tcp_connection(
3037 client: &mut crate::tls::GrpcClient,

Callers 1

service_forward_tcpFunction · 0.85

Calls 2

is_emptyMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected