Add --get-name flag

This commit is contained in:
Keivan-sf
2025-07-27 16:15:04 +03:30
parent bc5306ca87
commit f282a1ae4b
2 changed files with 34 additions and 19 deletions

View File

@@ -11,10 +11,16 @@ struct Cli {
socksport: Option<u16>,
#[arg(long, value_name = "httpport")]
httpport: Option<u16>,
#[arg(long, action = clap::ArgAction::SetTrue, value_name = "get-name")]
get_name: Option<bool>,
}
fn main() {
let cli = Cli::parse();
if cli.get_name == Some(true) {
print!("{}", parser::get_name(&cli.uri));
return;
}
let json_config = parser::create_json_config(&cli.uri, cli.socksport, cli.httpport);
println!("{}", json_config);
}

View File

@@ -9,6 +9,11 @@ mod uri_identifier;
mod vless;
mod vmess;
pub fn get_name(uri: &str) -> String {
let (_, data, _) = get_uri_data(uri);
return data.remarks;
}
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
let config = create_config(uri, socks_port, http_port);
let serialized = serde_json::to_string(&config).unwrap();
@@ -34,25 +39,7 @@ pub fn create_config(
}
pub fn create_outbound_object(uri: &str) -> config_models::Outbound {
let protocol = uri_identifier::get_uri_protocol(uri);
let (name, data, outbound_settings): (String, RawData, OutboundSettings) = match protocol {
Some(uri_identifier::Protocols::Vless) => {
let d = vless::data::get_data(uri);
let s = vless::create_outbound_settings(&d);
(String::from("vless"), d, s)
}
Some(uri_identifier::Protocols::Vmess) => {
let d = vmess::data::get_data(uri);
let s = vmess::create_outbound_settings(&d);
(String::from("vmess"), d, s)
}
Some(_) => {
panic!("The protocol was recognized but is not supported yet");
}
None => {
panic!("The protocol is not supported");
}
};
let (name, data, outbound_settings) = get_uri_data(uri);
let network_type = data.r#type.clone().unwrap_or(String::from(""));
let allow_insecure = data.allowInsecure == Some(String::from("true"))
@@ -161,3 +148,25 @@ pub fn create_outbound_object(uri: &str) -> config_models::Outbound {
return outbound;
}
fn get_uri_data(uri: &str) -> (String, RawData, OutboundSettings) {
let protocol = uri_identifier::get_uri_protocol(uri);
return match protocol {
Some(uri_identifier::Protocols::Vless) => {
let d = vless::data::get_data(uri);
let s = vless::create_outbound_settings(&d);
(String::from("vless"), d, s)
}
Some(uri_identifier::Protocols::Vmess) => {
let d = vmess::data::get_data(uri);
let s = vmess::create_outbound_settings(&d);
(String::from("vmess"), d, s)
}
Some(_) => {
panic!("The protocol was recognized but is not supported yet");
}
None => {
panic!("The protocol is not supported");
}
};
}