From 1040df03997d9144aaadb20df93c553147a73cc4 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sun, 17 May 2026 15:43:48 +0800 Subject: [PATCH] fix: update CLI for current client APIs --- src/cli.rs | 21 ++++++++++---- src/main.rs | 81 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 2f3b3550f..351a580f1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use hbb_common::{ config::PeerConfig, config::READ_TIMEOUT, - futures::{SinkExt, StreamExt}, + futures::StreamExt, log, message_proto::*, protobuf::Message as _, @@ -46,6 +46,7 @@ impl Session { false, None, None, + None, ); session } @@ -53,7 +54,7 @@ impl Session { #[async_trait] impl Interface for Session { - fn get_login_config_handler(&self) -> Arc> { + fn get_lch(&self) -> Arc> { return self.lc.clone(); } @@ -61,14 +62,20 @@ impl Interface for Session { match msgtype { "input-password" => { self.sender - .send(Data::Login((self.password.clone(), true))) + .send(Data::Login(( + String::new(), + String::new(), + self.password.clone(), + true, + ))) .ok(); } "re-input-password" => { log::error!("{}: {}", title, text); match rpassword::prompt_password("Enter password: ") { Ok(password) => { - let login_data = Data::Login((password, true)); + let login_data = + Data::Login((String::new(), String::new(), password, true)); self.sender.send(login_data).ok(); } Err(e) => { @@ -93,6 +100,8 @@ impl Interface for Session { self.lc.write().unwrap().handle_peer_info(&pi); } + fn set_multiple_windows_session(&self, _sessions: Vec) {} + async fn handle_hash(&self, pass: &str, hash: Hash, peer: &mut Stream) { log::info!( "password={}", @@ -137,8 +146,8 @@ pub async fn connect_test(id: &str, key: String, token: String) { Err(err) => { log::error!("Failed to connect {}: {}", &id, err); } - Ok((mut stream, direct)) => { - log::info!("direct: {}", direct); + Ok(((mut stream, _direct, _secure, _kcp, _typ), direct)) => { + log::info!("direct: {:?}", direct); // rpassword::prompt_password("Input anything to exit").ok(); loop { tokio::select! { diff --git a/src/main.rs b/src/main.rs index 9bc90a8fa..3d5237ab5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,49 +38,68 @@ fn main() { if !common::global_init() { return; } - use clap::App; + use clap::{Arg, ArgAction, Command}; use hbb_common::log; - let args = format!( - "-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]' - -c, --connect=[REMOTE_ID] 'test only' - -k, --key=[KEY] '' - -s, --server=[] 'Start server'", - ); - let matches = App::new("rustdesk") + let matches = Command::new("rustdesk") .version(crate::VERSION) .author("Purslane Ltd") .about("RustDesk command line tool") - .args_from_usage(&args) + .arg( + Arg::new("port-forward") + .short('p') + .long("port-forward") + .value_name("PORT-FORWARD-OPTIONS") + .help("Format: remote-id:local-port:remote-port[:remote-host]"), + ) + .arg( + Arg::new("connect") + .short('c') + .long("connect") + .value_name("REMOTE_ID") + .help("test only"), + ) + .arg(Arg::new("key").short('k').long("key").value_name("KEY")) + .arg( + Arg::new("server") + .short('s') + .long("server") + .action(ArgAction::SetTrue) + .help("Start server"), + ) .get_matches(); use hbb_common::{config::LocalConfig, env_logger::*}; init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); - if let Some(p) = matches.value_of("port-forward") { - let options: Vec = p.split(":").map(|x| x.to_owned()).collect(); + if let Some(p) = matches.get_one::("port-forward") { + let options: Vec = p.split(':').map(|x| x.to_owned()).collect(); if options.len() < 3 { log::error!("Wrong port-forward options"); return; } - let mut port = 0; - if let Ok(v) = options[1].parse::() { - port = v; - } else { - log::error!("Wrong local-port"); - return; - } - let mut remote_port = 0; - if let Ok(v) = options[2].parse::() { - remote_port = v; - } else { - log::error!("Wrong remote-port"); - return; - } + let port = match options[1].parse::() { + Ok(v) => v, + Err(_) => { + log::error!("Wrong local-port"); + return; + } + }; + let remote_port = match options[2].parse::() { + Ok(v) => v, + Err(_) => { + log::error!("Wrong remote-port"); + return; + } + }; let mut remote_host = "localhost".to_owned(); if options.len() > 3 { remote_host = options[3].clone(); } common::test_rendezvous_server(); common::test_nat_type(); - let key = matches.value_of("key").unwrap_or("").to_owned(); + let key = matches + .get_one::("key") + .map(String::as_str) + .unwrap_or("") + .to_owned(); let token = LocalConfig::get_option("access_token"); cli::start_one_port_forward( options[0].clone(), @@ -90,13 +109,17 @@ fn main() { key, token, ); - } else if let Some(p) = matches.value_of("connect") { + } else if let Some(p) = matches.get_one::("connect") { common::test_rendezvous_server(); common::test_nat_type(); - let key = matches.value_of("key").unwrap_or("").to_owned(); + let key = matches + .get_one::("key") + .map(String::as_str) + .unwrap_or("") + .to_owned(); let token = LocalConfig::get_option("access_token"); cli::connect_test(p, key, token); - } else if let Some(p) = matches.value_of("server") { + } else if matches.get_flag("server") { log::info!("id={}", hbb_common::config::Config::get_id()); crate::start_server(true, false); }