@@ -73,9 +73,13 @@ async fn main() -> fpm::Result<()> {
73
73
fpm:: stop_tracking ( & config, source, target) . await ?;
74
74
}
75
75
if let Some ( mark) = matches. subcommand_matches ( "serve" ) {
76
- let port = mark. value_of ( "port" ) . unwrap_or ( "8000" ) . to_string ( ) ;
76
+ let port = mark
77
+ . value_of ( "port" )
78
+ . unwrap_or ( mark. value_of ( "positional_port" ) . unwrap_or ( "8000" ) )
79
+ . to_string ( ) ;
80
+ let bind = mark. value_of ( "bind" ) . unwrap_or ( "127.0.0.1" ) . to_string ( ) ;
77
81
tokio:: task:: spawn_blocking ( move || {
78
- fpm:: serve ( port. as_str ( ) ) . expect ( "http service error" ) ;
82
+ fpm:: serve ( bind . as_str ( ) , port. as_str ( ) ) . expect ( "http service error" ) ;
79
83
} )
80
84
. await
81
85
. expect ( "Thread spawn error" ) ;
@@ -222,7 +226,24 @@ fn app(authors: &'static str, version: &'static str) -> clap::App<'static, 'stat
222
226
)
223
227
. subcommand (
224
228
clap:: SubCommand :: with_name ( "serve" )
225
- . arg ( clap:: Arg :: with_name ( "port" ) . required ( false ) )
229
+ . arg ( clap:: Arg :: with_name ( "port" )
230
+ . required_unless ( "positional_port" )
231
+ . required ( false )
232
+ . help ( "Specify the port to serve on" )
233
+ )
234
+ . arg ( clap:: Arg :: with_name ( "positional_port" )
235
+ . long ( "--port" )
236
+ . required_unless ( "bind" )
237
+ . takes_value ( true )
238
+ . required ( false )
239
+ . help ( "Specify the port to serve on" )
240
+ )
241
+ . arg ( clap:: Arg :: with_name ( "bind" )
242
+ . long ( "--bind" )
243
+ . takes_value ( true )
244
+ . required ( false )
245
+ . help ( "Specify the bind address to serve on" )
246
+ )
226
247
. about ( "Create an http server and serves static files" )
227
248
. version ( env ! ( "CARGO_PKG_VERSION" ) ) ,
228
249
)
0 commit comments