@@ -239,34 +239,40 @@ async fn fetch_oauth_metadata(client: &reqwest::Client, url: &str) -> Option<OAu
239239}
240240
241241pub fn open_in_browser ( url : & str ) -> Result < ( ) , Box < dyn Error > > {
242- #[ cfg( target_os = "macos" ) ]
243- {
244- let status = std:: process:: Command :: new ( "open" ) . arg ( url) . status ( ) ?;
245- if status. success ( ) {
246- return Ok ( ( ) ) ;
247- }
248- return Err ( "failed to launch browser with open" . into ( ) ) ;
249- }
250- #[ cfg( target_os = "windows" ) ]
251- {
252- let status = std:: process:: Command :: new ( "cmd" )
253- . args ( [ "/C" , "start" , "" , url] )
254- . status ( ) ?;
255- if status. success ( ) {
256- return Ok ( ( ) ) ;
257- }
258- return Err ( "failed to launch browser with start" . into ( ) ) ;
242+ open_in_browser_impl ( url)
243+ }
244+
245+ #[ cfg( target_os = "macos" ) ]
246+ fn open_in_browser_impl ( url : & str ) -> Result < ( ) , Box < dyn Error > > {
247+ let status = std:: process:: Command :: new ( "open" ) . arg ( url) . status ( ) ?;
248+ if status. success ( ) {
249+ return Ok ( ( ) ) ;
259250 }
260- #[ cfg( all( unix, not( target_os = "macos" ) ) ) ]
261- {
262- let status = std:: process:: Command :: new ( "xdg-open" ) . arg ( url) . status ( ) ?;
263- if status. success ( ) {
264- return Ok ( ( ) ) ;
265- }
266- return Err ( "failed to launch browser with xdg-open" . into ( ) ) ;
251+ Err ( "failed to launch browser with open" . into ( ) )
252+ }
253+
254+ #[ cfg( target_os = "windows" ) ]
255+ fn open_in_browser_impl ( url : & str ) -> Result < ( ) , Box < dyn Error > > {
256+ let status = std:: process:: Command :: new ( "cmd" )
257+ . args ( [ "/C" , "start" , "" , url] )
258+ . status ( ) ?;
259+ if status. success ( ) {
260+ return Ok ( ( ) ) ;
261+ }
262+ Err ( "failed to launch browser with start" . into ( ) )
263+ }
264+
265+ #[ cfg( all( unix, not( target_os = "macos" ) ) ) ]
266+ fn open_in_browser_impl ( url : & str ) -> Result < ( ) , Box < dyn Error > > {
267+ let status = std:: process:: Command :: new ( "xdg-open" ) . arg ( url) . status ( ) ?;
268+ if status. success ( ) {
269+ return Ok ( ( ) ) ;
267270 }
271+ Err ( "failed to launch browser with xdg-open" . into ( ) )
272+ }
268273
269- #[ allow( unreachable_code) ]
274+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , unix) ) ) ]
275+ fn open_in_browser_impl ( url : & str ) -> Result < ( ) , Box < dyn Error > > {
270276 Err ( format ! ( "no browser launcher configured for URL: {url}" ) . into ( ) )
271277}
272278
0 commit comments