mirror of
https://github.com/veeso/termscp.git
synced 2026-04-05 09:41:53 -07:00
refactor: split parser internals into focused modules
This commit is contained in:
19
src/utils/parser/ports.rs
Normal file
19
src/utils/parser/ports.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::filetransfer::FileTransferProtocol;
|
||||
|
||||
pub(super) fn default_port_for_protocol(protocol: FileTransferProtocol) -> u16 {
|
||||
match protocol {
|
||||
FileTransferProtocol::Ftp(_) => 21,
|
||||
FileTransferProtocol::Scp | FileTransferProtocol::Sftp => 22,
|
||||
_ => 22,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn parse_port(port: Option<regex::Match<'_>>, default: u16) -> Result<u16, String> {
|
||||
match port {
|
||||
Some(port) => port
|
||||
.as_str()
|
||||
.parse::<u16>()
|
||||
.map_err(|err| format!("Bad port \"{}\": {err}", port.as_str())),
|
||||
None => Ok(default),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user