mirror of
https://github.com/veeso/termscp.git
synced 2026-09-27 14:31:18 -07:00
Cargo clippy
This commit is contained in:
+6
-6
@@ -127,13 +127,13 @@ fn main() {
|
|||||||
if let Some(remote) = extra_args.get(0) {
|
if let Some(remote) = extra_args.get(0) {
|
||||||
// Parse address
|
// Parse address
|
||||||
match utils::parser::parse_remote_opt(remote) {
|
match utils::parser::parse_remote_opt(remote) {
|
||||||
Ok((addr, portn, proto, user, wrkdir)) => {
|
Ok(host_opts) => {
|
||||||
// Set params
|
// Set params
|
||||||
address = Some(addr);
|
address = Some(host_opts.hostname);
|
||||||
port = portn;
|
port = host_opts.port;
|
||||||
protocol = proto;
|
protocol = host_opts.protocol;
|
||||||
username = user;
|
username = host_opts.username;
|
||||||
remote_wrkdir = wrkdir;
|
remote_wrkdir = host_opts.wrkdir;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Bad address option: {}", err);
|
eprintln!("Bad address option: {}", err);
|
||||||
|
|||||||
@@ -228,14 +228,12 @@ impl Activity for AuthActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Read one event
|
// Read one event
|
||||||
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
if let Ok(Some(event)) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
||||||
if let Some(event) = event {
|
|
||||||
// Set redraw to true
|
// Set redraw to true
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
// Handle event
|
// Handle event
|
||||||
self.handle_input_event(&event);
|
self.handle_input_event(&event);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Redraw if necessary
|
// Redraw if necessary
|
||||||
if self.redraw {
|
if self.redraw {
|
||||||
// Draw
|
// Draw
|
||||||
|
|||||||
@@ -41,17 +41,11 @@ impl FileTransferActivity {
|
|||||||
/// Read one event.
|
/// Read one event.
|
||||||
/// Returns whether at least one event has been handled
|
/// Returns whether at least one event has been handled
|
||||||
pub(super) fn read_input_event(&mut self) -> bool {
|
pub(super) fn read_input_event(&mut self) -> bool {
|
||||||
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
if let Ok(Some(event)) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
||||||
// Iterate over input events
|
|
||||||
if let Some(event) = event {
|
|
||||||
// Handle event
|
// Handle event
|
||||||
self.handle_input_event(&event);
|
self.handle_input_event(&event);
|
||||||
// Return true
|
// Return true
|
||||||
true
|
true
|
||||||
} else {
|
|
||||||
// No event
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Error
|
// Error
|
||||||
false
|
false
|
||||||
@@ -103,7 +97,7 @@ impl FileTransferActivity {
|
|||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
// Handle quit event
|
// Handle quit event
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_disconnect_popup();
|
self.popup = Some(self.create_disconnect_popup());
|
||||||
}
|
}
|
||||||
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
||||||
KeyCode::Right => self.tab = FileExplorerTab::Remote, // <RIGHT> switch to right tab
|
KeyCode::Right => self.tab = FileExplorerTab::Remote, // <RIGHT> switch to right tab
|
||||||
@@ -269,7 +263,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
'q' | 'Q' => {
|
'q' | 'Q' => {
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_quit_popup();
|
self.popup = Some(self.create_quit_popup());
|
||||||
}
|
}
|
||||||
'r' | 'R' => {
|
'r' | 'R' => {
|
||||||
// Rename
|
// Rename
|
||||||
@@ -326,7 +320,7 @@ impl FileTransferActivity {
|
|||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
// Handle quit event
|
// Handle quit event
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_disconnect_popup();
|
self.popup = Some(self.create_disconnect_popup());
|
||||||
}
|
}
|
||||||
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
||||||
KeyCode::Left => self.tab = FileExplorerTab::Local, // <LEFT> switch to local tab
|
KeyCode::Left => self.tab = FileExplorerTab::Local, // <LEFT> switch to local tab
|
||||||
@@ -490,7 +484,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
'q' | 'Q' => {
|
'q' | 'Q' => {
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_quit_popup();
|
self.popup = Some(self.create_quit_popup());
|
||||||
}
|
}
|
||||||
'r' | 'R' => {
|
'r' | 'R' => {
|
||||||
// Rename
|
// Rename
|
||||||
@@ -547,7 +541,7 @@ impl FileTransferActivity {
|
|||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
// Handle quit event
|
// Handle quit event
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_disconnect_popup();
|
self.popup = Some(self.create_disconnect_popup());
|
||||||
}
|
}
|
||||||
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
|
||||||
KeyCode::Down => {
|
KeyCode::Down => {
|
||||||
@@ -586,7 +580,7 @@ impl FileTransferActivity {
|
|||||||
KeyCode::Char(ch) => match ch {
|
KeyCode::Char(ch) => match ch {
|
||||||
'q' | 'Q' => {
|
'q' | 'Q' => {
|
||||||
// Create quit prompt dialog
|
// Create quit prompt dialog
|
||||||
self.popup = self.create_quit_popup();
|
self.popup = Some(self.create_quit_popup());
|
||||||
}
|
}
|
||||||
_ => { /* Nothing to do */ }
|
_ => { /* Nothing to do */ }
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -62,23 +62,23 @@ impl FileTransferActivity {
|
|||||||
/// ### create_quit_popup
|
/// ### create_quit_popup
|
||||||
///
|
///
|
||||||
/// Create quit popup input mode (since must be shared between different input handlers)
|
/// Create quit popup input mode (since must be shared between different input handlers)
|
||||||
pub(super) fn create_disconnect_popup(&mut self) -> Option<Popup> {
|
pub(super) fn create_disconnect_popup(&mut self) -> Popup {
|
||||||
Some(Popup::YesNo(
|
Popup::YesNo(
|
||||||
String::from("Are you sure you want to disconnect?"),
|
String::from("Are you sure you want to disconnect?"),
|
||||||
FileTransferActivity::disconnect,
|
FileTransferActivity::disconnect,
|
||||||
FileTransferActivity::callback_nothing_to_do,
|
FileTransferActivity::callback_nothing_to_do,
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### create_quit_popup
|
/// ### create_quit_popup
|
||||||
///
|
///
|
||||||
/// Create quit popup input mode (since must be shared between different input handlers)
|
/// Create quit popup input mode (since must be shared between different input handlers)
|
||||||
pub(super) fn create_quit_popup(&mut self) -> Option<Popup> {
|
pub(super) fn create_quit_popup(&mut self) -> Popup {
|
||||||
Some(Popup::YesNo(
|
Popup::YesNo(
|
||||||
String::from("Are you sure you want to quit?"),
|
String::from("Are you sure you want to quit?"),
|
||||||
FileTransferActivity::disconnect_and_quit,
|
FileTransferActivity::disconnect_and_quit,
|
||||||
FileTransferActivity::callback_nothing_to_do,
|
FileTransferActivity::callback_nothing_to_do,
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### switch_input_field
|
/// ### switch_input_field
|
||||||
|
|||||||
@@ -441,8 +441,7 @@ impl SetupActivity {
|
|||||||
// Iterate over ssh keys
|
// Iterate over ssh keys
|
||||||
let mut ssh_keys: Vec<ListItem> = Vec::with_capacity(cli.iter_ssh_keys().count());
|
let mut ssh_keys: Vec<ListItem> = Vec::with_capacity(cli.iter_ssh_keys().count());
|
||||||
for key in cli.iter_ssh_keys() {
|
for key in cli.iter_ssh_keys() {
|
||||||
if let Ok(host) = cli.get_ssh_key(key) {
|
if let Ok(Some((addr, username, _))) = cli.get_ssh_key(key) {
|
||||||
if let Some((addr, username, _)) = host {
|
|
||||||
ssh_keys.push(ListItem::new(Span::from(format!(
|
ssh_keys.push(ListItem::new(Span::from(format!(
|
||||||
"{} at {}",
|
"{} at {}",
|
||||||
username, addr,
|
username, addr,
|
||||||
@@ -450,9 +449,6 @@ impl SetupActivity {
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Return list
|
// Return list
|
||||||
Some(
|
Some(
|
||||||
|
|||||||
@@ -168,14 +168,12 @@ impl Activity for SetupActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Read one event
|
// Read one event
|
||||||
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
if let Ok(Some(event)) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
||||||
if let Some(event) = event {
|
|
||||||
// Set redraw to true
|
// Set redraw to true
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
// Handle event
|
// Handle event
|
||||||
self.handle_input_event(&event);
|
self.handle_input_event(&event);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Redraw if necessary
|
// Redraw if necessary
|
||||||
if self.redraw {
|
if self.redraw {
|
||||||
// Draw
|
// Draw
|
||||||
|
|||||||
+84
-146
@@ -56,9 +56,17 @@ lazy_static! {
|
|||||||
static ref REMOTE_OPT_REGEX: Regex = Regex::new(r"(?:([a-z]+)://)?(?:([^@]+)@)?(?:([^:]+))(?::((?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])))?(?::([^:]+))?").ok().unwrap();
|
static ref REMOTE_OPT_REGEX: Regex = Regex::new(r"(?:([a-z]+)://)?(?:([^@]+)@)?(?:([^:]+))(?::((?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])))?(?::([^:]+))?").ok().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RemoteOptions {
|
||||||
|
pub hostname: String,
|
||||||
|
pub port: u16,
|
||||||
|
pub protocol: FileTransferProtocol,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub wrkdir: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
/// ### parse_remote_opt
|
/// ### parse_remote_opt
|
||||||
///
|
///
|
||||||
/// Parse remote option string. Returns in case of success a tuple made of (address, port, protocol, username, wrkdir)
|
/// Parse remote option string. Returns in case of success a RemoteOptions struct
|
||||||
/// For ssh if username is not provided, current user will be used.
|
/// For ssh if username is not provided, current user will be used.
|
||||||
/// In case of error, message is returned
|
/// In case of error, message is returned
|
||||||
/// If port is missing default port will be used for each protocol
|
/// If port is missing default port will be used for each protocol
|
||||||
@@ -75,18 +83,7 @@ lazy_static! {
|
|||||||
/// - sftp://172.26.104.1
|
/// - sftp://172.26.104.1
|
||||||
/// - ...
|
/// - ...
|
||||||
///
|
///
|
||||||
pub fn parse_remote_opt(
|
pub fn parse_remote_opt(remote: &str) -> Result<RemoteOptions, String> {
|
||||||
remote: &str,
|
|
||||||
) -> Result<
|
|
||||||
(
|
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
),
|
|
||||||
String,
|
|
||||||
> {
|
|
||||||
// Set protocol to default protocol
|
// Set protocol to default protocol
|
||||||
#[cfg(not(test))] // NOTE: don't use configuration during tests
|
#[cfg(not(test))] // NOTE: don't use configuration during tests
|
||||||
let mut protocol: FileTransferProtocol = match environment::init_config_dir() {
|
let mut protocol: FileTransferProtocol = match environment::init_config_dir() {
|
||||||
@@ -136,7 +133,7 @@ pub fn parse_remote_opt(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
// Get address
|
// Get address
|
||||||
let address: String = match groups.get(3) {
|
let hostname: String = match groups.get(3) {
|
||||||
Some(group) => group.as_str().to_string(),
|
Some(group) => group.as_str().to_string(),
|
||||||
None => return Err(String::from("Missing address")),
|
None => return Err(String::from("Missing address")),
|
||||||
};
|
};
|
||||||
@@ -152,7 +149,13 @@ pub fn parse_remote_opt(
|
|||||||
Some(group) => Some(PathBuf::from(group.as_str())),
|
Some(group) => Some(PathBuf::from(group.as_str())),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
Ok((address, port, protocol, username, wrkdir))
|
Ok(RemoteOptions {
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
protocol,
|
||||||
|
username,
|
||||||
|
wrkdir,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
None => Err(String::from("Bad remote host syntax!")),
|
None => Err(String::from("Bad remote host syntax!")),
|
||||||
}
|
}
|
||||||
@@ -217,168 +220,103 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_utils_parse_remote_opt() {
|
fn test_utils_parse_remote_opt() {
|
||||||
// Base case
|
// Base case
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 22);
|
assert_eq!(result.port, 22);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert!(result.3.is_some());
|
assert!(result.username.is_some());
|
||||||
// User case
|
// User case
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("root@172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("root@172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 22);
|
assert_eq!(result.port, 22);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert_eq!(result.3.unwrap(), String::from("root"));
|
assert_eq!(result.username.unwrap(), String::from("root"));
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// User + port
|
// User + port
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("root@172.26.104.1:8022"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("root@172.26.104.1:8022"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 8022);
|
assert_eq!(result.port, 8022);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert_eq!(result.3.unwrap(), String::from("root"));
|
assert_eq!(result.username.unwrap(), String::from("root"));
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// Port only
|
// Port only
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("172.26.104.1:4022"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("172.26.104.1:4022"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 4022);
|
assert_eq!(result.port, 4022);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert!(result.3.is_some());
|
assert!(result.username.is_some());
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// Protocol
|
// Protocol
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("ftp://172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("ftp://172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 21); // Fallback to ftp default
|
assert_eq!(result.port, 21); // Fallback to ftp default
|
||||||
assert_eq!(result.2, FileTransferProtocol::Ftp(false));
|
assert_eq!(result.protocol, FileTransferProtocol::Ftp(false));
|
||||||
assert!(result.3.is_none()); // Doesn't fall back
|
assert!(result.username.is_none()); // Doesn't fall back
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// Protocol
|
// Protocol
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("sftp://172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("sftp://172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 22); // Fallback to sftp default
|
assert_eq!(result.port, 22); // Fallback to sftp default
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert!(result.3.is_some()); // Doesn't fall back
|
assert!(result.username.is_some()); // Doesn't fall back
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("scp://172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("scp://172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 22); // Fallback to scp default
|
assert_eq!(result.port, 22); // Fallback to scp default
|
||||||
assert_eq!(result.2, FileTransferProtocol::Scp);
|
assert_eq!(result.protocol, FileTransferProtocol::Scp);
|
||||||
assert!(result.3.is_some()); // Doesn't fall back
|
assert!(result.username.is_some()); // Doesn't fall back
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// Protocol + user
|
// Protocol + user
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("ftps://anon@172.26.104.1"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("ftps://anon@172.26.104.1"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 21); // Fallback to ftp default
|
assert_eq!(result.port, 21); // Fallback to ftp default
|
||||||
assert_eq!(result.2, FileTransferProtocol::Ftp(true));
|
assert_eq!(result.protocol, FileTransferProtocol::Ftp(true));
|
||||||
assert_eq!(result.3.unwrap(), String::from("anon"));
|
assert_eq!(result.username.unwrap(), String::from("anon"));
|
||||||
assert!(result.4.is_none());
|
assert!(result.wrkdir.is_none());
|
||||||
// Path
|
// Path
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("root@172.26.104.1:8022:/var"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("root@172.26.104.1:8022:/var"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 8022);
|
assert_eq!(result.port, 8022);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert_eq!(result.3.unwrap(), String::from("root"));
|
assert_eq!(result.username.unwrap(), String::from("root"));
|
||||||
assert_eq!(result.4.unwrap(), PathBuf::from("/var"));
|
assert_eq!(result.wrkdir.unwrap(), PathBuf::from("/var"));
|
||||||
// Port only
|
// Port only
|
||||||
let result: (
|
let result: RemoteOptions = parse_remote_opt(&String::from("172.26.104.1:home"))
|
||||||
String,
|
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("172.26.104.1:home"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 22);
|
assert_eq!(result.port, 22);
|
||||||
assert_eq!(result.2, FileTransferProtocol::Sftp);
|
assert_eq!(result.protocol, FileTransferProtocol::Sftp);
|
||||||
assert!(result.3.is_some());
|
assert!(result.username.is_some());
|
||||||
assert_eq!(result.4.unwrap(), PathBuf::from("home"));
|
assert_eq!(result.wrkdir.unwrap(), PathBuf::from("home"));
|
||||||
// All together now
|
// All together now
|
||||||
let result: (
|
let result: RemoteOptions =
|
||||||
String,
|
parse_remote_opt(&String::from("ftp://anon@172.26.104.1:8021:/tmp"))
|
||||||
u16,
|
|
||||||
FileTransferProtocol,
|
|
||||||
Option<String>,
|
|
||||||
Option<PathBuf>,
|
|
||||||
) = parse_remote_opt(&String::from("ftp://anon@172.26.104.1:8021:/tmp"))
|
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.0, String::from("172.26.104.1"));
|
assert_eq!(result.hostname, String::from("172.26.104.1"));
|
||||||
assert_eq!(result.1, 8021); // Fallback to ftp default
|
assert_eq!(result.port, 8021); // Fallback to ftp default
|
||||||
assert_eq!(result.2, FileTransferProtocol::Ftp(false));
|
assert_eq!(result.protocol, FileTransferProtocol::Ftp(false));
|
||||||
assert_eq!(result.3.unwrap(), String::from("anon"));
|
assert_eq!(result.username.unwrap(), String::from("anon"));
|
||||||
assert_eq!(result.4.unwrap(), PathBuf::from("/tmp"));
|
assert_eq!(result.wrkdir.unwrap(), PathBuf::from("/tmp"));
|
||||||
// bad syntax
|
// bad syntax
|
||||||
assert!(parse_remote_opt(&String::from("omar://172.26.104.1")).is_err()); // Bad protocol
|
assert!(parse_remote_opt(&String::from("omar://172.26.104.1")).is_err()); // Bad protocol
|
||||||
assert!(parse_remote_opt(&String::from("omar://172.26.104.1:650000")).is_err());
|
assert!(parse_remote_opt(&String::from("omar://172.26.104.1:650000")).is_err());
|
||||||
|
|||||||
Reference in New Issue
Block a user