Skip to content

Commit

Permalink
allow both port and port-file
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Oct 20, 2024
1 parent 556599c commit caae7d8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions rs/pocket_ic_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct Args {
#[clap(long, short)]
ip_addr: Option<String>,
/// The port at which the PocketIC server should listen
#[clap(long, short)]
port: Option<u16>,
#[clap(long, short, default_value_t = 0)]
port: u16,
/// The file to which the PocketIC server port should be written
#[clap(long, conflicts_with = "port")]
#[clap(long)]
port_file: Option<PathBuf>,
/// The time-to-live of the PocketIC server in seconds
#[clap(long, default_value_t = TTL_SEC)]
Expand Down Expand Up @@ -119,8 +119,7 @@ async fn start(runtime: Arc<Runtime>) {
};

let ip_addr = args.ip_addr.unwrap_or("127.0.0.1".to_string());
let port = args.port.unwrap_or_default();
let addr = format!("{}:{}", ip_addr, port);
let addr = format!("{}:{}", ip_addr, args.port);
let listener = std::net::TcpListener::bind(addr.clone())
.unwrap_or_else(|_| panic!("Failed to bind PocketIC server to address {}", addr));
let real_port = listener.local_addr().unwrap().port();
Expand Down

0 comments on commit caae7d8

Please sign in to comment.