@@ -11,9 +11,9 @@ use crate::{
1111 interface:: { AppInterface , DevProcess , ExitReason , Interface } ,
1212 CommandExt , Result ,
1313} ;
14- use clap:: { ArgAction , Parser } ;
1514
1615use anyhow:: { bail, Context } ;
16+ use clap:: { ArgAction , Parser } ;
1717use log:: { error, info, warn} ;
1818use once_cell:: sync:: OnceCell ;
1919use shared_child:: SharedChild ;
@@ -88,7 +88,34 @@ fn command_internal(mut options: Options) -> Result<()> {
8888
8989fn local_ip_address ( ) -> & ' static IpAddr {
9090 static LOCAL_IP : OnceCell < IpAddr > = OnceCell :: new ( ) ;
91- LOCAL_IP . get_or_init ( || local_ip_address:: local_ip ( ) . expect ( "failed to resolve local IP address" ) )
91+ 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 ( )
116+ }
117+ }
118+ } )
92119}
93120
94121pub fn setup ( options : & mut Options , mobile : bool ) -> Result < AppInterface > {
0 commit comments