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

Function open_browser_url

crates/openshell-cli/src/auth.rs:179–210  ·  view source on GitHub ↗

Open a URL in the default browser.

(url: &str)

Source from the content-addressed store, hash-verified

177
178/// Open a URL in the default browser.
179pub fn open_browser_url(url: &str) -> std::result::Result<(), String> {
180 #[cfg(target_os = "macos")]
181 {
182 std::process::Command::new("open")
183 .arg(url)
184 .spawn()
185 .map_err(|e| format!("failed to run `open`: {e}"))?;
186 }
187
188 #[cfg(target_os = "linux")]
189 {
190 std::process::Command::new("xdg-open")
191 .arg(url)
192 .spawn()
193 .map_err(|e| format!("failed to run `xdg-open`: {e}"))?;
194 }
195
196 #[cfg(target_os = "windows")]
197 {
198 std::process::Command::new("cmd")
199 .args(["/C", "start", url])
200 .spawn()
201 .map_err(|e| format!("failed to open browser: {e}"))?;
202 }
203
204 #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
205 {
206 return Err("unsupported platform for browser opening".to_string());
207 }
208
209 Ok(())
210}
211
212/// Extract the origin (scheme + host) from a gateway endpoint URL.
213///

Callers 2

oidc_browser_auth_flowFunction · 0.85
browser_auth_flowFunction · 0.85

Calls 1

spawnMethod · 0.45

Tested by

no test coverage detected