@@ -21,10 +21,11 @@ fn command() -> Command {
2121 . version ( env ! ( "CARGO_PKG_VERSION" ) )
2222 . about ( "Server for TaskChampion" )
2323 . arg (
24- arg ! ( -p --port <PORT > "Port on which to serve" )
25- . help ( "Port on which to serve" )
26- . value_parser ( value_parser ! ( usize ) )
27- . default_value ( "8080" ) ,
24+ arg ! ( -l --listen <ADDRESS >)
25+ . help ( "Address and Port on which to listen on. Can be an IP Address or a DNS name followed by a colon and a port e.g. localhost:8080" )
26+ . value_parser ( ValueParser :: string ( ) )
27+ . action ( ArgAction :: Append )
28+ . required ( true ) ,
2829 )
2930 . arg (
3031 arg ! ( -d --"data-dir" <DIR > "Directory in which to store data" )
@@ -62,7 +63,6 @@ async fn main() -> anyhow::Result<()> {
6263 let matches = command ( ) . get_matches ( ) ;
6364
6465 let data_dir: & OsString = matches. get_one ( "data-dir" ) . unwrap ( ) ;
65- let port: usize = * matches. get_one ( "port" ) . unwrap ( ) ;
6666 let snapshot_versions: u32 = * matches. get_one ( "snapshot-versions" ) . unwrap ( ) ;
6767 let snapshot_days: i64 = * matches. get_one ( "snapshot-days" ) . unwrap ( ) ;
6868 let client_id_allowlist: Option < HashSet < Uuid > > = matches
@@ -75,16 +75,17 @@ async fn main() -> anyhow::Result<()> {
7575 } ;
7676 let server = WebServer :: new ( config, client_id_allowlist, SqliteStorage :: new ( data_dir) ?) ;
7777
78- log:: info!( "Serving on port {}" , port) ;
79- HttpServer :: new ( move || {
78+ let mut http_server = HttpServer :: new ( move || {
8079 App :: new ( )
8180 . wrap ( ErrorHandlers :: new ( ) . handler ( StatusCode :: INTERNAL_SERVER_ERROR , print_error) )
8281 . wrap ( Logger :: default ( ) )
8382 . configure ( |cfg| server. config ( cfg) )
84- } )
85- . bind ( format ! ( "0.0.0.0:{}" , port) ) ?
86- . run ( )
87- . await ?;
83+ } ) ;
84+ for listen_address in matches. get_many :: < & str > ( "listen" ) . unwrap ( ) {
85+ log:: info!( "Serving on {}" , listen_address) ;
86+ http_server = http_server. bind ( listen_address) ?
87+ }
88+ http_server. run ( ) . await ?;
8889 Ok ( ( ) )
8990}
9091
@@ -104,14 +105,19 @@ mod test {
104105
105106 #[ test]
106107 fn command_allowed_client_ids_none ( ) {
107- let matches = command ( ) . get_matches_from ( [ "tss" ] ) ;
108+ let matches = command ( ) . get_matches_from ( [ "tss" , "--listen" , "localhost:8080" ] ) ;
108109 assert_eq ! ( allowed( & matches) , None ) ;
109110 }
110111
111112 #[ test]
112113 fn command_allowed_client_ids_one ( ) {
113- let matches =
114- command ( ) . get_matches_from ( [ "tss" , "-C" , "711d5cf3-0cf0-4eb8-9eca-6f7f220638c0" ] ) ;
114+ let matches = command ( ) . get_matches_from ( [
115+ "tss" ,
116+ "--listen" ,
117+ "localhost:8080" ,
118+ "-C" ,
119+ "711d5cf3-0cf0-4eb8-9eca-6f7f220638c0" ,
120+ ] ) ;
115121 assert_eq ! (
116122 allowed( & matches) ,
117123 Some ( vec![ Uuid :: parse_str(
@@ -125,6 +131,8 @@ mod test {
125131 fn command_allowed_client_ids_two ( ) {
126132 let matches = command ( ) . get_matches_from ( [
127133 "tss" ,
134+ "--listen" ,
135+ "localhost:8080" ,
128136 "-C" ,
129137 "711d5cf3-0cf0-4eb8-9eca-6f7f220638c0" ,
130138 "-C" ,
@@ -141,7 +149,13 @@ mod test {
141149
142150 #[ test]
143151 fn command_data_dir ( ) {
144- let matches = command ( ) . get_matches_from ( [ "tss" , "--data-dir" , "/foo/bar" ] ) ;
152+ let matches = command ( ) . get_matches_from ( [
153+ "tss" ,
154+ "--data-dir" ,
155+ "/foo/bar" ,
156+ "--listen" ,
157+ "localhost:8080" ,
158+ ] ) ;
145159 assert_eq ! ( matches. get_one:: <OsString >( "data-dir" ) . unwrap( ) , "/foo/bar" ) ;
146160 }
147161
0 commit comments