use structopt::StructOpt; use clap::{Parser, Subcommand, Args}; const APP_TOKEN_ENV_NAME: &str = "PUNCH_TOKEN"; const APP_USER_ENV_NAME: &str = "PUNCH_USER"; const APP_PASS_ENV_NAME: &str = "PUNCH_PASS"; #[derive(Parser, Debug)] pub struct CommandLineInput2 { #[command(subcommand)] pub cmd: Commands, } #[derive(Subcommand, Debug)] pub enum Commands { Login(UserLogin), TokenLogin(TokenLogin), /// if logined in, just start, /// else, use the token to login, and start AutoRun(TokenLogin), /// after login, we can use start to /// connect to the remote Start, Info, /// exits the Stop, } #[derive(Args, Debug)] pub struct UserLogin { #[arg(short, long, env = APP_USER_ENV_NAME)] pub username: String, #[arg(short, long, env = APP_PASS_ENV_NAME, required=false)] pub password: String, } #[derive(Args, Debug)] pub struct TokenLogin { #[arg(long, env=APP_TOKEN_ENV_NAME, required=false)] pub token: String, } #[derive(StructOpt, Debug)] pub struct CommandLineInput { #[structopt(short="u", long = "user", default_value = "", help="specify a token")] pub user: String, #[structopt(short="P", long = "pass", default_value = "", help="specify a token")] pub pass: String, #[structopt(short="t", long = "token", default_value = "", help="specify a token")] pub token: String, #[structopt(short = "p", long = "port", default_value = "0", help="which port to use")] pub port: u16, #[structopt(short= "h", long = "hostname", default_value="", help="specify the hostname")] pub hostname: String, } #[derive(StructOpt, Debug)] pub struct CommandLine { #[structopt(short = "s", long = "sn", default_value = "127.0.0.1:7655")] pub sn: String, #[structopt(short = "t", long = "tcp", default_value = "127.0.0.1:7656")] pub quic: String, /// in the format of "localhost:1234" #[structopt(long = "nat1")] pub nat_server1: String, /// in the format of "localhost:1234" #[structopt(long = "nat2")] pub nat_server2: String, #[structopt(short = "r")] pub _allow_routing: bool, #[structopt(short = "dm")] pub _drop_multicast: bool, #[structopt( help = "ttl of the register udp4 packet", short = "L", default_value = "1" )] pub register_ttl: u8, #[structopt(help = "mtu of the tun", short = "m", default_value = "1290")] pub mtu: u32, #[structopt(short = "n", long = "name", default_value = "test-name")] pub name: String, #[structopt(long = "tos", default_value = "0")] pub tos: u32, // #[structopt(long = "token", default_value = "")] // pub token: String, // #[structopt(long = "code", default_value = "")] // pub network_code: String, #[structopt(short = "p")] pub allow_p2p: bool, #[structopt(short = "l")] pub local_port: u16, } impl Clone for CommandLine { fn clone(&self) -> Self { Self { sn: self.sn.clone(), quic: self.quic.clone(), _allow_routing: self._allow_routing, _drop_multicast: self._drop_multicast, register_ttl: self.register_ttl, mtu: self.mtu, local_port: self.local_port, name: self.name.clone(), tos: self.tos, // token: self.token.clone(), // network_code: self.network_code.clone(), allow_p2p: self.allow_p2p, nat_server1: self.nat_server1.clone(), nat_server2: self.nat_server2.clone(), } } }