aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-06-02 04:05:45 +0000
committerFuwn <[email protected]>2021-06-02 04:05:45 +0000
commite4a3d642a64b0c15d127f040419d805e2f0dff34 (patch)
treee00cbfea71068a113fe8aaca672d8cd4fa133b15 /src/cli.rs
parentrefactor(clippy): strictor clippy constraints (diff)
downloadnitrous-e4a3d642a64b0c15d127f040419d805e2f0dff34.tar.xz
nitrous-e4a3d642a64b0c15d127f040419d805e2f0dff34.zip
feat(check): proxy support
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/cli.rs b/src/cli.rs
index d3525d5..f5cc080 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,6 +1,8 @@
// Copyleft (ɔ) 2021-2021 Fuwn
// SPDX-License-Identifier: GPL-3.0-only
+use std::str::FromStr;
+
use structopt::{
clap,
clap::{App, Arg, SubCommand},
@@ -8,6 +10,26 @@ use structopt::{
use crate::nitrous::Nitrous;
+pub enum ProxyType {
+ Http,
+ Socks4,
+ Socks5,
+ Tor,
+}
+impl FromStr for ProxyType {
+ type Err = &'static str;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "http" => Ok(Self::Http),
+ "socks4" => Ok(Self::Socks4),
+ "socks5" => Ok(Self::Socks5),
+ "tor" => Ok(Self::Tor),
+ _ => Err("no match"),
+ }
+ }
+}
+
pub struct Cli;
impl Cli {
pub async fn execute() {
@@ -43,6 +65,19 @@ impl Cli {
}
},
debug,
+ ProxyType::from_str(
+ matches
+ .subcommand_matches("check")
+ .unwrap()
+ .value_of("proxy_type")
+ .unwrap(),
+ )
+ .unwrap(),
+ matches
+ .subcommand_matches("check")
+ .unwrap()
+ .value_of("proxy_list")
+ .unwrap_or("null"),
)
.await;
}
@@ -76,8 +111,24 @@ impl Cli {
Arg::with_name("file")
.required(false)
.takes_value(true)
- .index(1),
- ),
+ .long("file")
+ .short("f"),
+ )
+ .args(&[
+ Arg::with_name("proxy_type")
+ .required(true)
+ .takes_value(true)
+ .index(1)
+ .possible_values(&["http", "socks4", "socks5", "tor"]),
+ Arg::with_name("proxy_list")
+ .required_ifs(&[
+ ("proxy_type", "http"),
+ ("proxy_type", "socks4"),
+ ("proxy_type", "socks5"),
+ ])
+ .takes_value(true)
+ .index(2),
+ ]),
])
.arg(
Arg::with_name("debug")