refactor: split parser internals into focused modules

This commit is contained in:
Christian Visintin
2026-03-21 13:18:08 +01:00
parent 9a8833ef60
commit b26b6db94b
5 changed files with 264 additions and 339 deletions

19
src/utils/parser/ports.rs Normal file
View 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),
}
}