forked from ekzhang/bore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
73 lines (62 loc) · 1.88 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use anyhow::Result;
use bore_cli::{client::Client, server::Server};
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[clap(author, version, about)]
#[clap(propagate_version = true)]
struct Args {
#[clap(subcommand)]
command: Command,
}
#[derive(Subcommand, Debug)]
enum Command {
/// Starts a local proxy to the remote server.
Local {
/// The local port to expose.
local_port: u16,
/// The local host to expose.
#[clap(short, long, value_name = "HOST", default_value = "localhost")]
local_host: String,
/// Address of the remote server to expose local ports to.
#[clap(short, long)]
to: String,
/// Optional port on the remote server to select.
#[clap(short, long, default_value_t = 0)]
port: u16,
/// Optional secret for authentication.
#[clap(short, long, env = "BORE_SECRET", hide_env_values = true)]
secret: Option<String>,
},
/// Runs the remote proxy server.
Server {
/// Minimum TCP port number to accept.
#[clap(long, default_value_t = 1024)]
min_port: u16,
/// Optional secret for authentication.
#[clap(short, long, env = "BORE_SECRET", hide_env_values = true)]
secret: Option<String>,
},
}
#[tokio::main]
async fn run(command: Command) -> Result<()> {
match command {
Command::Local {
local_host,
local_port,
to,
port,
secret,
} => {
let client = Client::new(&local_host, local_port, &to, port, secret.as_deref()).await?;
client.listen().await?;
}
Command::Server { min_port, secret } => {
Server::new(min_port, secret.as_deref()).listen().await?;
}
}
Ok(())
}
fn main() -> Result<()> {
tracing_subscriber::fmt::init();
run(Args::parse().command)
}