From 330054352b05a3ec1973144ab5582c4077d03ab9 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Thu, 6 Apr 2023 13:04:44 +0330 Subject: [PATCH] [Feat]: ports flag is available --- Cargo.toml | 2 +- readme.md | 6 +++--- src/main.rs | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a0cbe1..6e26dd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "absolutus_rex" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/readme.md b/readme.md index 1ae81a9..958f674 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Absolutus Rex -**absolutus_rex** is a CLI tool to forward ports. The name means "Absolute King" in Latin. It is currently on version 0.1.0. +**absolutus_rex** is a CLI tool to forward ports. The name means "Absolute King" in Latin. It is currently on version 0.2.0. ## Usage @@ -29,14 +29,14 @@ sequenceDiagram ### Options -- `-p, --port `: Local port - requires a local port that is available for use [default: 8990] +- `-p, --ports `: Local port - requires a local port that are available for use - `-l, --local-only`: This flag only opens a port on the local network (127.0.0.1), and is intended for debugging purposes - `-a, --r-address `: This flag sets the remote address - `--r-port `: This flag sets the remote port - `-h, --help`: Print help (see more with '--help') - `-V, --version`: Print version -Note: The `--r-address` and `--r-port` options are required. +Note: The `--r-address`, `--r-port` and `--ports` options are required. ## Installation diff --git a/src/main.rs b/src/main.rs index 7ddba4b..e9c3e3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,9 @@ use std::fmt; long_about = "Absolutus Rex is a command-line tool for port forwarding.\n\nThis tool can be used to forward ports, and may be particularly useful when used with `supervisord`." )] struct Args { - /// Local port - requires a local port that is available for use. - #[arg(short, long, default_value_t = 8990)] - port: u16, + /// Local ports - requires local ports that are available for use. + #[arg(short, long)] + ports: Vec, /// This flag only opens a port on the local network (127.0.0.1), and is intended for debugging purposes. #[arg(short, long, default_value_t = false)] @@ -29,16 +29,17 @@ fn main() { let args = Args::parse(); let remote = fmt::format(format_args!("{}:{}", args.remote_address, args.remote_port)); println!("Application ran with config:"); - println!("\tPort: `{}`", args.port); println!("\tIs Local Only: {}!", args.local_only); println!("\tRemote Address: `{}`", remote); - match TcpProxy::new(args.port, remote.parse().unwrap(), args.local_only) { - Ok(_proxy) => { - println!("Proxy State: OK!"); - } - e => { - println!("Proxy State: ERROR!"); - println!("Reason: {}", e.err().unwrap()); + for port in args.ports { + match TcpProxy::new(port, remote.parse().unwrap(), args.local_only) { + Ok(_proxy) => { + println!("\tPort: {},Proxy State: OK!", port); + } + e => { + println!("Port: {},Proxy State: ERROR!", port); + println!("Reason: {}", e.err().unwrap()); + } } }