@@ -89,32 +89,39 @@ fn command_internal(mut options: Options) -> Result<()> {
8989pub fn local_ip_address ( ) -> & ' static IpAddr {
9090 static LOCAL_IP : OnceCell < IpAddr > = OnceCell :: new ( ) ;
9191 LOCAL_IP . get_or_init ( || {
92- let addresses: Vec < IpAddr > = local_ip_address:: list_afinet_netifas ( )
93- . expect ( "failed to list networks" )
94- . into_iter ( )
95- . map ( |( _, ipaddr) | ipaddr)
96- . filter ( |ipaddr| match ipaddr {
97- IpAddr :: V4 ( i) => i != & Ipv4Addr :: LOCALHOST ,
98- _ => false ,
99- } )
100- . collect ( ) ;
101- match addresses. len ( ) {
102- 0 => panic ! ( "No external IP detected." ) ,
103- 1 => {
104- let ipaddr = addresses. first ( ) . unwrap ( ) ;
105- log:: info!( "Detected external IP {ipaddr}." ) ;
106- * ipaddr
107- }
108- _ => {
109- let selected = dialoguer:: Select :: with_theme ( & dialoguer:: theme:: ColorfulTheme :: default ( ) )
110- . with_prompt ( "What external IP should we use for your development server?" )
111- . items ( & addresses)
112- . default ( 0 )
113- . interact ( )
114- . expect ( "failed to select external IP" ) ;
115- * addresses. get ( selected) . unwrap ( )
92+ let ip = local_ip_address:: local_ip ( ) . unwrap_or_else ( |_| {
93+ let addresses: Vec < IpAddr > = local_ip_address:: list_afinet_netifas ( )
94+ . expect ( "failed to list networks" )
95+ . into_iter ( )
96+ . map ( |( _, ipaddr) | ipaddr)
97+ . filter ( |ipaddr| match ipaddr {
98+ IpAddr :: V4 ( i) => i != & Ipv4Addr :: LOCALHOST ,
99+ _ => false ,
100+ } )
101+ . collect ( ) ;
102+ match addresses. len ( ) {
103+ 0 => panic ! ( "No external IP detected." ) ,
104+ 1 => {
105+ let ipaddr = addresses. first ( ) . unwrap ( ) ;
106+ * ipaddr
107+ }
108+ _ => {
109+ let selected = dialoguer:: Select :: with_theme ( & dialoguer:: theme:: ColorfulTheme :: default ( ) )
110+ . with_prompt (
111+ "Failed to detect external IP, What IP should we use to access your development server?" ,
112+ )
113+ . items ( & addresses)
114+ . default ( 0 )
115+ . interact ( )
116+ . expect ( "failed to select external IP" ) ;
117+ * addresses. get ( selected) . unwrap ( )
118+ }
116119 }
117- }
120+ } ) ;
121+
122+ log:: info!( "Using {ip} to access the development server." ) ;
123+
124+ ip
118125 } )
119126}
120127
0 commit comments