Skip to content

Commit

Permalink
feat: cli add specify port
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhazhazhu committed Jan 26, 2024
1 parent c698c5d commit 94ede0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ pub struct AirncConfig {
/// Whether to disable the link remote service
#[clap(long = "service-disable", global = true)]
pub service_disable: bool,
/// Specify a port number
#[clap(short, long = "port", global = true)]
pub port: Option<u16>,
}

impl Default for AirncConfig {
fn default() -> Self {
Self {
service_disable: false,
port: None,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ pub async fn run_server(cli: Cli) -> Result<(), std::io::Error> {

let state = AppState { file_path };
let local_ip = get_local_ip().unwrap();
let port = find_available_port();
let port = if let Some(port) = cli.config.port {
port
} else {
find_available_port()
};
let addr: SocketAddr = SocketAddr::new(local_ip, port);
let download_url = format!("http://{}/{}", addr.to_string(), &file_name);

Expand Down

0 comments on commit 94ede0e

Please sign in to comment.